由于工作需要,需要mysql mybatis springmvc 分页,
if(null!=request.getParameter("rows")){//每页行数
pwhere.setPageSize(Integer.parseInt(request.getParameter("rows")));
}
if(null!=request.getParameter("page")){//当前页
int page=(Integer.parseInt(request.getParameter("page"))-1)*pwhere.getPageSize();
pwhere.setPage(page);
}
-----------------------------------
@RequestMapping(value = "/advertise/list", method = RequestMethod.GET)@ResponseBody
public GridDataModel<Advertise> advertiseList() throws UnsupportedEncodingException{
GridDataModel<Advertise> model = new GridDataModel<Advertise>();
Map<String, Object> map = new HashMap<String, Object>();
String language = request.getParameter("lan");
String posiCodeSearch = request.getParameter("posiCodeSearch");
String statusSearch = request.getParameter("statusSearch");
String titleName = request.getParameter("titleName");
if(StringUtils.isNotEmpty(titleName)) {
//titleName = URLDecoder.decode(titleName, "UTF-8");
titleName =java.net.URLDecoder.decode(titleName, "UTF-8");
}
/*if(StringUtils.isNotEmpty(brandClass)) {
brandClass = URLDecoder.decode(brandClass, "UTF-8");
}*/ //&& !"all".equals(language)
if (null != language && !"0".equals(language)) {
map.put("lan", language);
}
if (null != posiCodeSearch && "" != posiCodeSearch && !"0".equals(posiCodeSearch)) {
map.put("posiCode", posiCodeSearch);
}
if (null != statusSearch && "" != statusSearch && !"-1".equals(statusSearch)) {
map.put("status", statusSearch);
}
if (null != titleName && "" != titleName && !"0".equals(titleName)) {
map.put("title",titleName);
}
String startStr = request.getParameter(Constants.Page.START);
String limitStr = request.getParameter(Constants.Page.LIMIT);
int start = Integer.parseInt(StringUtils.isBlank(startStr) ? Constants.Page.FIRST : startStr);
int limit = Integer.parseInt(StringUtils.isBlank(limitStr) ? Constants.Page.PAGE_SIZE : limitStr);
if (limit == 0) {
limit = Integer.MAX_VALUE;
}
int total = advertisesService.getCountBySearch(map);
int end = start + limit;
end = end > total ? total : end;
map.put("start", start);
map.put("end", end + 1);
List<Advertise> adList = advertisesService.getBySearch(map);
model.setRows(adList);
model.setTotal(total);
return model;
}