package com.dao;
import java.util.List;
import org.hibernate.Query;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.dto.Leader;
import com.util.PageUtils;
public class LeaderDao extends HibernateDaoSupport{
public List LeaderList(PageUtils pu, String mohu) {
String hql = " from Leader ";
if(mohu!=null){
hql+=" where name like '%"+mohu+"%' ";
}
Query query = getSession().createQuery(hql).setFirstResult(pu.getStartIndex()).setMaxResults(pu.getTotalPage());
List list = query.list();
return list;
}
public List deptList(Leader leader) {
// TODO Auto-generated method stub
return getHibernateTemplate().find("from Dept");
}
public Leader getLeader(Leader leader) {
// TODO Auto-generated method stub
Leader leader1 = (Leader) getHibernateTemplate().get(Leader.class, leader.getId());
return leader1;
}
public int saveOrUpdate(Leader leader) {
// TODO Auto-generated method stub
try {
getHibernateTemplate().saveOrUpdate(leader);
return 1;
} catch (DataAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
public Integer getCount(String mohu) {
String hql =" select count(*) from Leader ";
if(mohu!=null){
hql+=" where name like '%"+mohu+"%' ";
}
Query query = getSession().createQuery(hql);
Integer count = Integer.valueOf(query.uniqueResult().toString());
return count;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 thansitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'list.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-conthol" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" href="css/index_work.css" type="text/css"></link><script type="text/javascript" src="js/jquery-1.8.2.js"></script></head>
<script type="text/javascript">
function mohu(){
var mohu = $("[name='mohu']").val();
location = "l_list?mohu="+mohu;
}
function gopage(cpage){
location = "l_list?cpage="+cpage;
}
</script>
<body>
<table>
<tr>
<th colspan="21">
<input type="text" name="mohu" value="${mohu}"><input type="button" value="查询" onclick="mohu()">
</th>
</tr>
<tr>
<th>id</th>
<th>name</th>
<th>sex</th>
<th>hobby</th>
<th>tel</th>
<th>address</th>
<th>did</th>
<th>department</th>
<th>content</th>
<th>datea</th>
<th><input type="button" value="添加" onclick="location='update.jsp'"></th>
</tr>
<c:forEach var="l" items="${LeaderList}">
<tr>
<th>${l.id}</th>
<th>${l.name}</th>
<th>${l.sex}</th>
<th>${l.hobby}</th>
<th>${l.tel}</th>
<th>${l.address}</th>
<th>${l.d.did}</th>
<th>${l.d.department}</th>
<th>${l.d.content}</th>
<th>${l.d.datea}</th>
<th><input type="button" value="修改" onclick="location='update.jsp?id=${l.id}'"></th>
</tr>
</c:forEach>
<tr>
<th colspan="21">
<button onclick="gopage(1)">首页</button>
<button onclick="gopage(${pu.prevPage})">上页</button>
<button onclick="gopage(${pu.nextPage})">下页</button>
<button onclick="gopage(${pu.totalPage})">尾页</button>
第${pu.cpage}页/共${pu.totalPage}页/共${pu.count}条数据
</th>
</tr>
</table>
</body>
</html>
待人友善是修养,独来独往是性格。