1:控制层
一般查询和分页是一块的,所以写在一个功能里,即【findAll】和【findPageList】合并
@RequestMapping
public String index(@RequestParam Map<String,String> filters,
Model model){
//1. 调用业务层的方法分页查询Admin
PageInfo<Admin> pageInfo = adminService.findPage(filters);
//2. 将查询到的adminList存储到请求域中
model.addAttribute("page",pageInfo);
//3. 将搜索条件存储到请求域中
model.addAttribute("filters",filters);
//4. 返回逻辑视图
return PAGE_INDEX;
}
2:业务层(实现类)
向下传递的参数有过滤条件filters
@Override
public PageInfo<Admin> findPage(Map<String, String> filters) {
//1. 使用分页插件开启分页
PageHelper.startPage(CastUtil.castInt(filters.get("pageNum"),1),CastUtil.castInt(filters.get("pageSize"),10));
//2. 调用持久层的方法根据搜索条件进行搜索
List<Admin> adminList = adminMapper.findPageList(filters);
//10代表最多显示10个页码
return new PageInfo<>(adminList,10);
}
3:持久层(接口)
只需要返回【集合数据】即可
List<Admin> findPageList(Map<String, String> filters);
4:持久层(映射)
<select id="findPageList" resultType="Admin">
SELECT <include refid="columns"></include>
FROM acl_admin
<where>
<if test="username != null and username != ''">
username LIKE CONCAT("%",#{username},"%")
</if>
<if test="name != null and name != ''">
AND name LIKE CONCAT("%",#{name},"%")
</if>
<if test="phone != null and phone != ''">
AND phone LIKE CONCAT(#{phone},"%")
</if>
<if test="createTimeBegin != null and createTimeBegin != ''">
AND create_time >= #{createTimeBegin}
</if>
<if test="createTimeEnd != null and createTimeEnd != ''">
AND create_time <= #{createTimeEnd}
</if>
AND is_deleted = 0
</where>
ORDER BY create_time DESC
</select>