首页>代码>S2SH简单用户注册登录实例>/ideaLogin/src/net/hgdonline/dao/impl/UserDaoImpl.java
package net.hgdonline.dao.impl;
import net.hgdonline.dao.UserDao;
import net.hgdonline.pojo.User;
import org.hibernate.SessionFactory;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 雄伟
 * Date: 13-10-9
 * Time: 下午7:32
 * To change this template use File | Settings | File Templates.
 */
@Transactional
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class UserDaoImpl implements  UserDao  {
    private SessionFactory sessionFactory;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public void saveUser(User user) {
        System.out.println(user.getUsername());
        System.out.println(user.getPassword());
        this.getSessionFactory().getCurrentSession().save(user);
    }

    @Override
    public User findUser(User user) {
        User firstUser = new User();
        StringBuffer hql  =  new StringBuffer("from User user where user.username = '")
                .append(user.getUsername()).append("' and user.password = '")
                .append(user.getPassword()) .append("'");
        List<User> userList = this.getSessionFactory().getCurrentSession(). createQuery(hql.toString()).list();
        if(userList.size()>0) firstUser = userList.get(0);
        return firstUser;

    }
}


最近下载更多
jiemomo  LV12 2023年10月19日
and123456  LV11 2022年2月11日
1029162867  LV13 2021年11月8日
1065466539  LV1 2021年1月16日
mrmrmr2333  LV4 2020年11月6日
aaron2953  LV11 2020年9月1日
123sacac  LV1 2020年6月17日
ahuan123  LV4 2020年6月10日
2410068425  LV23 2020年6月1日
leikelin  LV8 2020年5月20日
最近浏览更多
qiwwwww  LV2 2024年6月19日
jiemomo  LV12 2023年10月19日
llkroot11  LV1 2022年11月15日
yut1an  LV2 2022年10月31日
wjh12345654321  LV14 2022年9月14日
谢谢谢谢谢谢你  LV6 2022年7月19日
q14769613 2022年7月15日
暂无贡献等级
阿时23428  LV15 2022年5月11日
chenhan413  LV10 2022年5月5日
and123456  LV11 2022年2月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友