📄 type1dao.java
字号:
package cn.handson.dao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.handson.base.*;
import cn.handson.utils.*;
public class Type1Dao {
/*
* 此方法用来得到所有的用户对象。。。
*
*
*/
public List loadAllType1() {
// TODO Auto-generated method stub
Session session=HibernateUtil.currentSession();
Transaction tx=session.beginTransaction();//定义一个事务
String sql="select b from Type1 as b";
Query query=session.createQuery(sql);
List list=query.list();
tx.commit();//提交事务
//HibernateUtil.closeSession();
return list;
}
/*
* 此方法用来删除用户对象.....
*
*/
public boolean deleteType1(Type1 te){
Session session=HibernateUtil.currentSession();
Transaction tx=session.beginTransaction();//定义一个事务
session.delete(te);
tx.commit();//提交事务
//HibernateUtil.closeSession();
return true;
}
/*
* 此方法用来通过ID来得到一个用户的对象。。。
*
*
*/
public Type1 getType1ById(Integer id) {
// TODO Auto-generated method stub
Session session=HibernateUtil.currentSession();
Transaction tx=session.beginTransaction();//定义一个事务
Type1 us=(Type1)session.get(Type1.class, id);
tx.commit();//提交事务
//HibernateUtil.closeSession();
return us;
}
/*
* 此方法用来更新数据库中的用户。。。
*
*/
public void updateType1(Type1 te) {
// TODO Auto-generated method stub
Session session=HibernateUtil.currentSession();
Transaction tx=session.beginTransaction();//定义一个事务
Type1 us=(Type1)session.get(Type1.class, te.getTypeId());
us.setConstructs(te.getConstructs());
us.setTypeTitle(te.getTypeTitle());
us.setTypeDesc(te.getTypeDesc());
session.save(us);
tx.commit();//提交事务
//HibernateUtil.closeSession();
}
/*
* 此方法用来添加用户。。。。
* User是页面传来的属性。。。
*
*/
public void addType1(Type1 te) {
// TODO Auto-generated method stub
Session session=HibernateUtil.currentSession();
Transaction tx=session.beginTransaction();//定义一个事务
session.save(te);
tx.commit();//提交事务
//HibernateUtil.closeSession();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -