【数据表格】datatable+SpringMVC+Spring Data JPA

初步实现

$("#userTable").dataTable({
    "processing": true,
    "serverSide": true,
    "searching": false,
    "bSort": false,
    "bPaginate": true,
    "pageLength": 10,
    "pagingType": "full_numbers",
    ajax: "/admin/user/list",
    columns: [
        {'title': '序号', data: 'id'},
        {'title': '账号', data: 'account'},
        {'title': '密码', data: 'pwd'},
        {'title': '性别', data: 'sex'},
        {
            'title': '操作', data: 'id', render: function () {
                return(
                    "<div class='tpl-table-black-operation'>"+
                        "<a href='javascript:;'>"+
                        "<i class='am-icon-pencil'></i> 编辑"+
                        "</a>"+
                        "<a href='javascript:;' class='tpl-table-black-operation-del'>"+
                        "<i class='am-icon-trash'></i> 删除"+
                        "</a>"+
                    "</div>"
                );
            }
        }
    ]
});
@ApiOperation(value = "用户列表api")
@GetMapping("/list")
@ResponseBody
public HashMap<String, Object> userList(Integer start, Integer length, HttpServletRequest request) {
    HashMap<String, Object> map = new HashMap<>();
    Pageable pageable = new PageRequest(start / length, length);
    Page<User> page = userService.findAll(pageable);
    map.put("length", length);
    map.put("recordsTotal", page.getTotalElements());
    map.put("recordsFiltered", page.getTotalElements());
    map.put("data", page.getContent());
    return map;
}

2、封装

...

上一篇:spring + springMVC + spring Data + jpa + maven 项目框架搭建


下一篇:javaweb各种框架组合案例(四):maven+spring+springMVC+spring data jpa(hibernate)【失败案例】