/**
* Erpusers entity.
*
* @author MyEclipse Persistence Tools
*/
public class Erpusers implements java.io.Serializable {
// Fields
/**用户表的POJO类
*
*/
private static final long serialVersionUID = 9208967468706594562L;
private Long UId;
private String username;
private String password;
private String userType;
private String userLock;
// Constructors
/** default constructor */
public Erpusers() {
}
/** minimal constructor */
public Erpusers(String username, String password) {
this.username = username;
this.password = password;
}
/** full constructor */
public Erpusers(String username, String password, String userType,
String userLock) {
this.username = username;
this.password = password;
this.userType = userType;
this.userLock = userLock;
}
// Property accessors
public Long getUId() {
return this.UId;
}
public void setUId(Long UId) {
this.UId = UId;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserType() {
return this.userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
public String getUserLock() {
return this.userLock;
}
public void setUserLock(String userLock) {
this.userLock = userLock;
}
}
2.DAO接口代码
package com.cici.erp.dao;
import java.util.List;
import com.cici.erp.model.Erpusers;
public interface ErpusersDAO {
//数据库操作接口
public void insert(Erpusers eu);
public void update(Erpusers eu);
public void delete(Erpusers eu);
@SuppressWarnings("unchecked")
public List getUsers();
public Erpusers getUser(String id);
@SuppressWarnings("unchecked")
public List getByGive(String cond);
}
3.DAO接口实现类代码
package com.cici.erp.dao.hibernate;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.cici.erp.dao.ErpusersDAO;
import com.cici.erp.model.Erpusers;
public class ErpusrsDaoHiber implements ErpusersDAO {
// 实现对底层数据库中数据的CIUD操作
private Session session = null;
public ErpusrsDaoHiber() {
// 在构造方法中实例化Session对象
Configuration config = new Configuration().configure();// 找到Hibernate配置
SessionFactory factory = config.buildSessionFactory();// 从配置中取出SessionFactory
this.session = factory.openSession();// 从工厂中取出一个Session
}
public void insert(Erpusers eu) {
// 插入一条新记录
Transaction tran = this.session.beginTransaction();
this.session.save(eu);
tran.commit();
this.session.close();
}
public void update(Erpusers eu) {
// 更新已有记录
Transaction tran = this.session.beginTransaction();// 事务开始
this.session.update(eu);// 执行语句
tran.commit();// 事务提交
this.session.close();
}
public void delete(Erpusers eu) {
// 删除数据
Transaction tran = this.session.beginTransaction();// 开始事物
this.session.delete(eu);// 执行语句
tran.commit();// 事务提交
}
@SuppressWarnings("unchecked")
public List getByGive(String cond) {
// 按指定用户名查询
List l = null;
String hql = "FROM Erpusers as eu WHERE eu.username like ?";
Query q = this.session.createQuery(hql);
q.setString(0, "%" + cond + "%");
l = q.list();
this.session.close();// 关闭session
return l;
}
@SuppressWarnings("unchecked")
public Erpusers getUser(String id) {
// 按ID查询数据
Erpusers eu=null;
return eu;
<< 上一页 [11] [12] [13] [14] [15] 下一页