package com.jxust.svsh.dao; import java.util.List; import javax.annotation.Resource; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.stereotype.Repository; import com.jxust.svsh.entity.Person; //用于标注数据访问的组件,dao组件 @Repository public class PersonDAO { @Resource private SessionFactory sessionFactory; private Session getSession() { return sessionFactory.getCurrentSession(); } /** * 根据id查询 * @param id * @return */ public Person getPersonById(String id) { return (Person) this.getSession().createQuery("from Person where id=?").setParameter(0, id).uniqueResult(); } /** * 添加 * @param person */ public void addPerson(Person person) { this.getSession().save(person); } /** * 更新 * @param person */ public void updatePerson(Person person) { this.getSession().update(person); } /** * 删除 * @param id */ public void deletePersonById(String id) { this.getSession().createQuery("delete Person where id=?").setParameter(0, id).executeUpdate(); } /** * 查询所有 * @return */ @SuppressWarnings("unchecked") public List<Person> getPersons() { return this.getSession().createCriteria(Person.class).list(); } }
最近下载更多
zhengwei_147 LV1
2023年6月11日
3516569014 LV5
2023年5月7日
lvchengliang LV4
2022年6月15日
1798139161 LV4
2022年2月7日
大彬 LV2
2021年12月13日
漫长的白日梦 LV8
2021年12月4日
没有鱼 LV3
2021年8月17日
8 LV1
2021年6月24日
吹星落雨 LV1
2021年6月22日
和味道江森 LV1
2021年4月17日