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日
最近浏览更多
奋斗的小蚂蚁 LV17
10月17日
quartz LV8
2024年7月1日
ma406805131 LV19
2024年6月28日
y_x_happy LV4
2024年6月25日
普米亚 LV1
2024年6月22日
17380184110
2024年6月18日
暂无贡献等级
微信网友_6040315240812544 LV8
2024年5月25日
asddwh LV13
2023年12月25日
WBelong LV8
2023年12月11日
Henew168 LV2
2023年11月19日

