controller:
/**
* 查询所有用户/查找指定用户
* 分页+搜索
*
*/
@RequestMapping("/findClientBySize")
@ResponseBody
public String findClientBySize(ClientUser clientUser,String userPhone,String userName, Integer currentPage, Integer pageSize)throws Exception{
if(currentPage == null || currentPage.equals("")){
currentPage = 1;
}
if(pageSize == null || currentPage.equals("")){
pageSize = 10;
}
int startRow = (currentPage-1)*pageSize;
int endRow = pageSize;
List<ClientUser>list= clientUserService.findAllClient(clientUser);
List<ClientUser> list2= clientUserService.findClientBySize(clientUser,userPhone,userName,startRow,endRow);
PageResult pageResult = new PageResult(currentPage,list.size(),pageSize,list2);
return JSON.toJSONString(pageResult);
}
domain:
package com.hpwl.domain;
import java.util.List;
/**
* Created by mayn on 2019/1/15.
*/
public class PageResult {
private int currentPage;//当前页
private int prevPage;//上一页
private int nextPage;//下一页
private int countSize;//一共几条数据
private int maxPage;//最后一页
private int pageSize;//每页显示条数
private List dataList;//返回的数据集
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPrevPage() {
return prevPage;
}
public void setPrevPage(int prevPage) {
this.prevPage = prevPage;
}
public int getNextPage() {
return nextPage;
}
public void setNextPage(int nextPage) {
this.nextPage = nextPage;
}
public int getCountSize() {
return countSize;
}
public void setCountSize(int countSize) {
this.countSize = countSize;
}
public int getMaxPage() {
return maxPage;
}
public void setMaxPage(int maxPage) {
this.maxPage = maxPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public List getDataList() {
return dataList;
}
public void setDataList(List dataList) {
this.dataList = dataList;
}
public PageResult(int currentPage, int countSize, int pageSize,List dataList) {
super();
this.currentPage = currentPage;
this.countSize = countSize;
this.pageSize = pageSize;
this.dataList = dataList;
this.prevPage = currentPage > 1 ? this.currentPage - 1 : 1;
this.maxPage = countSize % pageSize == 0 ? countSize/pageSize : countSize/pageSize+1;
this.nextPage = currentPage >= maxPage ? maxPage :currentPage + 1;
}
public PageResult() {
super();
}
}
mapper:
List<ClientUser> findClientBySize(ClientUser clientUser, @Param("userPhone")String userPhone, @Param("userName")String userName, @Param("startRow")int startRow, @Param("endRow")int endRow);
mapper.xml:
<select id="findClientBySize" resultType="ClientUser" >
select * from
client_user
<where>
1=1
<if test="userName!=null and userName!='' ">
and user_name=#{userName}
</if>
<if test="userPhone!=null and userPhone!=''">
and user_phone=#{userPhone}
</if>
</where>
limit
#{startRow},#{endRow}
</select>
jsp页面
<script type="text/javascript">
function toPage(currentPage){
$.ajax({
url:"${pageContext.request.contextPath}/AdminClient/findClientBySize",
data:{"currentPage":currentPage},
type: 'POST',
dataType: 'json',
success: function(data){
var a=null;
/*var jsonData = JSON.parse(data); //jsonData是该下路下的所有区间(json格式)
*/
var data1=data.dataList;
console.log(data);
console.log(data.dataList);
$("tbody").html('');
$.each(data1,function (index,obj) {
var tr0 = '<tr class="text-c">' +
'<td><input type="checkbox" value="'+obj.id+'" name=""></td>' +
'<td><u style="cursor:pointer" class="text-primary">'+obj.userName+'</u></td>' +
'<td>'+obj.userPwd+'</td>'+
'<td>'+obj.usernick+'</td>'+
'<td>'+obj.userPhone+'</td>'+
'<td>'+obj.datetime+'</td>'+
'<td>'+obj.chack+'</td>'+
'<td>'+obj.userName+'</td>'+
'<td class="td-manage">'+
'<a style="text-decoration:none" onClick="member_start(\'this\','+obj.id+')" href="javascript:;" title="启用"><i class="Hui-iconfont"></i></a> '+
'<a style="text-decoration:none" onClick="member_stop(\'this\','+obj.id+')" href="javascript:;" title="停用"><i class="Hui-iconfont"></i></a> '+
'<a title="编辑" href="javascript:;" οnclick="member_edit(\'编辑\',\'member-up.jsp\','+obj.id+',\'800\',\'510\')" class="ml-5" style="text-decoration:none">'+
'<i class="Hui-iconfont"></i></a> <a style="text-decoration:none" class="ml-5" onClick="change_password(\'修改密码\',\'change-password.jsp\','+obj.id+',\'600\',\'270\')" href="javascript:;" title="修改密码">'+
'<i class="Hui-iconfont"></i></a> <a title="删除" href="javascript:;" οnclick="" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a></td>'+
'</tr>';
$("tbody").append(tr0);
});
$("tfoot").html('');
var tr1 = '<tr class="text-c"><td colspan="10" style="text-align: right"> <a href="javascript:toPage('+data.prevPage+')" >上一页</a> <a href="javascript:toPage('+data.nextPage+')" >下一页</a></td></tr>';
$("tfoot").append(tr1);
},
});
};
$(function(){
toPage(1);
});