?? personservicebean.java
字號:
package cn.itcast.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.itcast.bean.Person;
import cn.itcast.service.PersonService;
@Transactional
public class PersonServiceBean implements PersonService {
//按名稱來找
@Resource private SessionFactory sessionFactory;
public void save(Person person){
sessionFactory.getCurrentSession().persist(person);
}
//person為游離狀態。
public void update(Person person){
sessionFactory.getCurrentSession().merge(person);
}
//按id來得到person
@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
public Person getPerson(Integer personid){
return (Person)sessionFactory.getCurrentSession().get(Person.class, personid);
}
//按ID來DELETE DATA
public void delete(Integer personid){
sessionFactory.getCurrentSession().delete(
sessionFactory.getCurrentSession().load(Person.class, personid) );
}
// get all person
@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
@SuppressWarnings("unchecked")
public List<Person> getPersons(){
return sessionFactory.getCurrentSession().createQuery("from Person").list();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -