我用ajax来显示列表和做其他操作,因为ajax无法往model和session里存值,所以我在上一页下一页那里取得值就是第一次进去界面时session里的值,他就只能在第一页和第二页之间跳,因为他取得值一直都是1和2,不知道这里该怎么写解决
//成功后展示列表函数
function showMedicineList(json) {
let list = json.data.list;
var html = "";
for (var i = 0; i < list.length; i++) {
html += "<tr>" +
"<td align= 'center'>" + "<input type='checkbox' name= 'medicineListCheckBox' value =" + list[i].mid + ">" + "</td>" +
"<td align= 'center' height='80'>" + list[i].mid + "</td>" +
"<td align= 'center'>" + list[i].mname + "</td>" +
"<td align= 'center'>" + list[i].mprice + "</td>" +
"<td align= 'center'>" + list[i].type + "</td>" +
"<td align='center'>" +
"<button class= 'btn btn-info' >" + "<a href=/01_ssm_integration_war_exploded/findMedicineByMid/" + list[i].mid + ">" + "<font color='white'>" + "修改" + "</font>" + "</a>" + "</button>"
+ "</td>" +
"<td align='center'>" +
"<button id = 'deleteMedicine' class='btn btn-danger' onclick= deleteMedicine(" + list[i].mid + ") >" +
"<font color='white'>" + "删除" + "</font>" + "</button>" +
"</td>" +
"</tr>"
}
html += "<td align='center'>" + "共<" + json.data.total + ">条记录" + "</td>"
html += "<td align='center'>" + "共<" + json.data.pages + ">页" + "</td>"
html += "<td align='center'>" + "当前第<" + json.data.pageNum + ">页" + "</td>"
html += "<td>"
html += "<button onclick='firstPage()'> " + "首页" + "</button>"
html += "<button onclick='prePage(${pageNum})'> " + "上一页" + "</button>"
html += "<button onclick='nextPage(${pageNum},${pages})'> " + "下一页" + "</button>"
html += "<button onclick='lastPage(${pages})'> " + "尾页" + "</button>"
html += "</td>"
$("#testBody").html(html);
}
@RequestMapping("/medicineList")
@ResponseBody
public JsonResult<PageInfo> medicineList(@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){
PageHelper.startPage(pageNum,5);
List<Medicine> data = medicineService.findMedicineList();
PageInfo<Medicine> pageInfo = new PageInfo<>(data);
session.setAttribute("pages",pageInfo.getPages());
System.out.println(pageNum);
session.setAttribute("pageNum",pageInfo.getPageNum());
return new JsonResult<>(200,pageInfo);
}
你干嘛不用 elementUI的table来实现呢 列表都不用你这样去写 超简单的
下一页 ,和上一页 时 都要 让 页数加一