userdao.java
来自「Spring +Web 的完整 MyEclipse 项目源码,使用者可以作为入门」· Java 代码 · 共 42 行
JAVA
42 行
/*
* Created on 2005-9-4
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.bid.hibernate;
import net.sf.hibernate.*;
import com.bid.domain.User;
import com.bid.exceptions.InfrastructureException;
/**
* @author Ma Dou
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class UserDAO {
/**
*
*/
public UserDAO() {
super();
// TODO Auto-generated constructor stub
HibernateUtil.beginTransaction();
}
public User getUserById(Long userId) throws InfrastructureException{
//HibernateUtil.beginTransaction();
Session session = HibernateUtil.currentSession();
User user = null;
try {
user = (User) session.load(User.class, userId);
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
return user;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?