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

📄 bookmessageop.java

📁 在eclipse平台下写的
💻 JAVA
字号:
/**
 * 
 */
package com.internetshop.hibernate.book_message;

import java.util.List;

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

/**
 * @author Echo_Me
 *
 */
public class BookMessageOp 
{
	//在Hibernate中,所有的操作都是通过Session完成
	// 此Session不同于JSP的Session
	private Session session = null ;
	private String searchName = null;
	private String type =null;
	// 在构造方法之中实例化session对象
	public BookMessageOp(String researchcontent, String type)
	{
		// 找到Hibernate配置
		Configuration config = new Configuration().configure() ;
		// 从配置中取出SessionFactory
		SessionFactory factory = config.buildSessionFactory() ;
		// 从SessionFactory中取出一个Session
		this.session = factory.openSession() ;
		this.searchName=researchcontent;
		this.type = type;
	}
	// 模糊查询
	public List getObjectList() {
		// TODO Auto-generated method stub
		Query query = this.session.createQuery(this.getHqlString(this.type));
		query.setString(0, "%"+this.searchName+"%");
		List list = query.list();
		return list;
	}
	
	public String getHqlString(String type)
	{
		String hql=null;
		int searType = Integer.parseInt(type);
		switch(searType)
		{
			case 1:hql="from BookMessage where book_name like ?";break;
			case 2:hql="from BookMessage where author like ?";break;
			case 3:hql="from BookMessage where publish like ?";break;
			case 4:hql="from BookMessage where book_ISBN like ?";break;
		}
		return hql;
	}
}

⌨️ 快捷键说明

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