1、 BaseDAO
需求:
按名字分页查询对应书籍信息
package com.eight.dao;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.query.Query;
/**
* 作用:
* 1.将赋值的操作交给basedao
* 2.分页:
* a 符合条件的总记录数
* b 查询符合条件的某一页记录
*
* @author pc
*
*/
public class BaseDao {
/**
* 赋值的操作
* @param query预定义对象
* @param map 前台传递过来的参数
*/
private void setParameter(Query query,Map<String, Object> map) {
// query.setParameter("bookName", "%"+book.getBookName+"%");
if(map == null || map.size() == 0) {
return;
}
Object value = null;
for(Map.Entry<String, Object> entry:map.entrySet()) {
value = entry.getValue();
if(value instanceof Collection) {
query.setParameterList(entry.getKey(), (Collection)value);
}else if (value instanceof Object[]){
query.setParameterList(entry.getKey(), (Object[