标签:style blog http io ar color os sp java
步骤:
1.新建new-other
2.选择Junit Test Case
3.注意红线圈出部分
4.选择需要测试的方法
5.Finish后出现如下
示例代码:
package com.jrgc.dao; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; import com.jrgc.entity.User; import com.jrgc.util.SessionUtil; public class UserDaoImp implements UserDao{ @SuppressWarnings("unchecked") @Override public List<User> userList() { Session session = SessionUtil.getSession(); /** * from User中的User是实体类(entity) */ String hql = "from User"; return session.createQuery(hql).list(); } @Override public void save(User u) { Session session = SessionUtil.getSession(); Transaction tran = session.beginTransaction(); try { session.save(u); tran.commit(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); tran.rollback(); }finally{ SessionUtil.closeSession(); } } }
标签:style blog http io ar color os sp java
原文地址:http://www.cnblogs.com/thinksasa/p/4147308.html