public List<Courier> findAll(boolean limit, int offset, int pageNumber) {
return courierDao.findall(limit,offset,pageNumber);
}
3.4controller层与前端交互
@ResponseBody("/courier/list.do")
public String list(HttpServletRequest req, HttpServletResponse resp){
CourierServiceImpl courierService = new CourierServiceImpl();
//接收前端传来的offset
int offset = Integer.parseInt(req.getParameter("offset"));
//接受pageNumber
int pageNumber = Integer.parseInt(req.getParameter("pageNumber"));
//接收查询结果
List<Courier> list = courierService.findAll(true,offset,pageNumber);
//这里单独对数据进行了转换,便于向前端展示(例如时间可能是不便查看)
List<LastCourier> list2 = new ArrayList<>();
for (Courier c:list) {
String register_time = String.valueOf(c.getRegister_time());
String login_time = String.valueOf(c.getLogin_time());
LastCourier lastCourier = new LastCourier();
lastCourier.setId(c.getId());
lastCourier.setName(c.getName());
lastCourier.setPhone(c.getPhone());
lastCourier.setID_Number(c.getID_Number());
lastCourier.setPassword(c.getPassword());
lastCourier.setSend_number(c.getSend_number());
lastCourier.setRegister_time(register_time);
lastCourier.setLogin_time(login_time);
list2.add(lastCourier);
}
//我这里有但单独的方法获取总数,获取总数可以写一个sql查询语句,查询总数
ExpressServiceImpl expressService = new ExpressServiceImpl();
List<Map<String,Integer>> console = expressService.console();
/**
* 总数
*/
Integer total = console.get(2).get("data_size");
/**
* 下面代码是将数据转换成bootstrapTable识别的形式(主要是总数,和数据存入数组,在数组里边一个值是一行的数据)
*/
ResultData<LastCourier> resultData = new ResultData<>();
resultData.setTotal(total);
resultData.setRows(list2);
//转换成json传递给前端
String json = JSONUtil.toJSON(resultData);
return json;
}
3.5bootstrapTable识别的形式类的编写
public class ResultData<T> {
private int total;
private List rows;
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
}