⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 informationdaoimpl.java

📁 一个采用J2EE技术实现的企业协同工作台
💻 JAVA
字号:
package common.work.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
//import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

import common.work.bean.Information;
import common.work.bean.Userlogin;

public class InformationDAOImpl implements InformationDAO {

	private SessionFactory sessionFactory;
	
	public InformationDAOImpl(){}
	
	public InformationDAOImpl(SessionFactory sessionFactory){
		this.sessionFactory = sessionFactory;
	}
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	/*public InformationDAOImpl(){  //产生相应的SessionFactory
		Configuration config = new Configuration();
		factory = config.configure().buildSessionFactory();
	}*/
	
	//通过相应的信息查询的方法
	public Information findByinformationname(String informationname) {
		// TODO Auto-generated method stub
		return (Information) this.findByproperty("informationname", informationname).get(0);
	}
    
	//通过工作名称来查询
	public List<Information> findByworkname(String workname) {
		// TODO Auto-generated method stub
		return this.findByproperty("workname", workname);
	}
	//
	public List<Information> findtype(String type) {
		// TODO Auto-generated method stub
		return this.findByproperty("type", type);
	}

    //修改数据记录中的相应属性
	public void Update(Information instance) {
		// TODO Auto-generated method stub
		Session session = sessionFactory.openSession();
		session.update(instance);
		session.beginTransaction().commit();
		session.close();
	}

    //删除相应的数据记录
	public void delete(Information instance) {
		// TODO Auto-generated method stub
		Session session = sessionFactory.openSession();
		session.delete(instance);
		session.beginTransaction().commit();
		session.close();
	}

     
	public List<Information> findByExample(Information instance) {
		// TODO Auto-generated method stub
		return null;
	}

     //通过信息表中的用户Id查询
	public Information findById(Integer id) {
		// TODO Auto-generated method stub
		Session session = sessionFactory.openSession();
		Information inform =(Information) session.get(Information.class, id);
		session.close();
		return inform;
	}

     //通过信息表中的任意字段属性查询
	public List<Information> findByproperty(String property, String value) {
		// TODO Auto-generated method stub
		Session session = sessionFactory.openSession();
		String hql = "from Information inform where inform."+property+" like ?";
		Query query = session.createQuery(hql);
		query.setString(0, "%"+value+"%");
		List<Information> user = query.list();
		session.close();
		return user;
	}
	
     //在用户信息表中插入数据记录
	public void save(Information instance) {
		// TODO Auto-generated method stub
        Session session = sessionFactory.openSession();
        session.save(instance);
        session.beginTransaction().commit();
        session.close();
	}

	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -