要求:
- data-th-mc-attr-str-url="@{/role}":对应的controller层@RequestMapping("/role")访问路径
- mc-attr-str-field=“name”:需与bean层的字段/数据库字段的驼峰命名法一致
- 请求方式:推荐post — mc-attr-str-method=“post”
- 提供监听方式:方便后面表头,行的新增编辑删除操作等,lay-filter=“roles”
数据表格
<div id="list" class="magicalcoder-table layui-anim layui-anim-fadein"
mc-attr-bool-loading="true" data-th-mc-attr-str-url="@{/role}"
mc-attr-str-toolbar="#tableToolbar" mc-attr-json-default-toolbar="[]"
mc-attr-bool-page="true" mc-attr-bool-even="true" lay-filter="roles"
mc-attr-str-method="post" mc-attr-str-title="角色管理"
mc-attr-json-where='{"status":1}'>
<span class="magicalcoder-table-th" mc-attr-str-field="id"
mc-attr-str-type="checkbox"></span> <span
class="magicalcoder-table-th" mc-attr-str-field="id">ID</span> <span
class="magicalcoder-table-th" mc-attr-str-field="name">名称</span>
<span class="magicalcoder-table-th" mc-attr-str-toolbar="#tableColToolbar">操作</span>
</div>
后端代码
@PostMapping
@ResponseBody
public Result fing(
//page:开始页面,可以通过这个来改变页编号
@RequestParam(name = "page",required = false, defaultValue = "1")Integer page,
//limit:每页数据量
@RequestParam(name = "limit",required = false, defaultValue = "10")Integer limit,
Role role) {
PageHelper.startPage(page, limit);
List<Role> list = roleService.find(role);
PageInfo<Role> pageInfo = new PageInfo<>(list);
Result r = Result.success();
r.addItem("count", pageInfo.getTotal());
r.addItem("data", list);
r.setMsg("查询成功");
return r;
}
插件pagehelper
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>