麻烦哪位大神帮我弄的分页 下面我会贴出我的代码,我用的是Hibernate+spring+jsp
用maven写的 如果大神有工具类就帮我整合下吧 十分感谢 在线急等
dao层实现
/*
* @(#) usersDaoImpl.java 2015年12月9日
*
* Copyright (c) 2015,RongHui Technology. All Rights Reserved.
* WWW.RHTECH.NET CONFIDENTIAL
*/
package com.ronghui.dao;
import java.util.List;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import com.ronghui.model.User;
@Repository("usersDao")
public class usersDaoImpl implements usersDao {
// extends BaseDaoImpl<UserEntity, Integer>
@Resource
protected SessionFactory sessionFactory;
public Session getSession() {
return sessionFactory.getCurrentSession();
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
//用户是否存在
@Override
public boolean isExist(User user) {
Session session = this.getSession();
String hql = "from User where name =? and pwd = ?";
Query query = session.createQuery(hql);
query.setString(0, user.getName());
query.setString(1, user.getPwd());
if (query.list().size() >= 1) {
return true;
}
return false;
}
//显示
@Override
public List<User> listInfo() {
// TODO Auto-generated method stub
String hql="from User";
Query query=(Query)this.getSession().createQuery(hql);
List<User> list=query.list();
return list;
}
//模糊查询
@Override
public List<User> vagueInfo(String name) {
// TODO Auto-generated method stub
String hql ="from User e where e.name like '%"+name+"%'";
Query query =getSession().createQuery(hql);
List<User> vaguelist =query.list();
return vaguelist;
}
}
}
service
/*
* @(#) usersServiceImpl.java 2015年12月9日
*
* Copyright (c) 2015,RongHui Technology. All Rights Reserved.
* WWW.RHTECH.NET CONFIDENTIAL
*/
package com.ronghui.service;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ronghui.dao.usersDao;
import com.ronghui.model.User;
@Transactional
@Service("usersService")
public class usersServiceImpl implements usersService {
@Resource
private usersDao usersDao;
@Override
public boolean isExist(User user) {
// TODO Auto-generated method stub
return usersDao.isExist(user);
}
@Override
public List<User> listInfo() {
// TODO Auto-generated method stub
return usersDao.listInfo();
}
@Override
public void delete(int id) {
// TODO Auto-generated method stub
usersDao.delete(id);
}
@Override
public User listId(int id) {
// TODO Auto-generated method stub
return usersDao.listId(id);
}
@Override
public List<User> vagueInfo(String name) {
// TODO Auto-generated method stub
return usersDao.vagueInfo(name);
}
}
controller
/**
*
*/
package com.ronghui.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ronghui.model.User;
import com.ronghui.service.usersService;
@Controller
public class UserController {
@Autowired
private usersService usersService;
private String name;
@ResponseBody
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public Map<String, Object> login(User user) {
Map<String, Object> map = new HashMap<String, Object>();
boolean loginResult = usersService.isExist(user);
map.put("loginResult", loginResult);
return map;
}
//测试
@RequestMapping(value = "/test", method = RequestMethod.GET) public
String getupdate() {
return "test";
}
@RequestMapping(value = "/content", method = RequestMethod.GET) public
String getcontent() {
return "content";
}
@RequestMapping(value = "/add", method = RequestMethod.GET) public
String getadd() {
return "addUser";
}
// list显示
@RequestMapping(value = "/mian", method = RequestMethod.GET)
public String userlogin(ModelMap model) {
List list = usersService.listInfo();
model.addAttribute("list", list);
return "mian";
}
//模糊查询
@RequestMapping("vague")
public String vague(String name,ModelMap model){
List list=usersService.vagueInfo(name);
model.addAttribute("list", list);
return "mian";
}
}
jsp
<body id="7" style="background-image: url('static/images/bj3.jpg');">
<div id="st-container" class="st-container">
<!-- content push wrapper -->
<div class="st-pusher" id="5">
<div class="st-content" id="4">
<!-- this is the wrapper for the content -->
<div class="st-content-inner" id="3">
<header class="codrops-header">
<h1 style="color: #48a770">
ChenHonest Administrate <span>User information management
case</span>
</h1>
</header>
<div class="main clearfix" id="2">
<div id="st-trigger-effects" class="column"
style="padding-left: 0px; padding-right: 18px;">
<form action="vague" method="post">
<div class="form-group">
<div class="field">
<div class="input-group">
<span class="addbtn">
<button type="button"
class="button bg-green-light icon-search"></button>
</span> <input id="vague" type="text" class="input" name="name"
size="50" placeholder="用户名关键词" /><span class="addbtn">
<button type="submit" class="button bg-green-light">搜索</button>
</span>
</div>
</div>
</div>
</form>
<br>
<table class="table table-hover"
style="line-height: 35px; color: #48a770;">
<tr>
<th width="400">用户名</th>
<th width="600">昵称</th>
<th width="200">年龄</th>
<th width="1000">操作</th>
</tr>
<c:if test="${empty list}">
<tr style="height: 340px;">
<td align="center" colspan=4><h3>未找到内容</h3></td>
</tr>
</c:if>
<c:forEach var="item" items="${list}">
<tr id="content">
<th width="400"><a href="con?id=${item.id}">${item.name }</a></th>
<th width="600"><a href="upd?id=${item.id}">${item.nice_name }</a></th>
<th width="200"><a href="upd?id=${item.id}">${item.age }</a></th>
<th width="1000"><a
class="button border-dot button-little"
href="delete?id=${item.id}" onclick="return confirm('确认删除?')">删除</a>
<a class="button border-dot button-little"
href="upd?id=${item.id}">修改</a>
</th>
</tr>
</c:forEach>
</table>
<br>
<br>
<button data-effect="st-effect-11">更多功能</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
``
我的邮箱jcnotnull0108@163.com 希望大神最好能在我发的代码基础上增加 不然直接给我工具类 我也不是太明白 谢谢 代码有点多所以我删掉了一些毕竟问题他描述要10000字以内