初学hibernate,只学了对数据库最简单的增、删、改、查!
public UserInfo login(int userid){
Configuration cfg=new Configuration().configure();
SessionFactory sf=cfg.buildSessionFactory();
Session session=sf.openSession();
UserInfo user=(UserInfo) session.get(UserInfo.class, userid);
session.close();
return user;
}
public void regUser(UserInfo user){
Configuration cfg=new Configuration().configure();
SessionFactory sf=cfg.buildSessionFactory();
Session session=sf.openSession();
Transaction tran=session.beginTransaction();
session.save(user);
tran.commit();
session.close();
}
等等.....
如何写三层,dao、service