1.写好SQL语句-在查询所有用户列表的基础上
<select id="like" resultType="org.krt.system.entity.User" parameterType="java.util.Map">
select * from sys_user
<if test="username != null">
where username like CONCAT(CONCAT('%', #{username}), '%')
</if>
limit #{start},#{limit}
</select>
2.业务逻辑代码-controller
@RequestMapping(value="admin/demo/journalList")
public String likeUsername(Model model,int start,int limit,String username) {
Map<String,Object> map = new HashMap<String,Object>();
map.put("username", username);
map.put("start", (start -1 ) * limit);
map.put("limit", limit);
List<User> list = userService.findLike(map);
model.addAttribute("list", list);
model.addAttribute("map", map);
return "admin/demo/journalList";
}
3.页面传值,引入JQ控件
<script>
$('#light-pagination').pagination({
pages: Math.ceil(50),//总页数
cssStyle: 'light-theme',
displayedPages: 10, //显示的按钮数量
edges: 1, //是否分开显示
hrefTextPrefix:'<%=basePath %>admin/demo/journalList?username=${map.username }&limit=3&start=',//跳转地址前缀
hrefTextSuffix:3,//每页显示多少条
currentPage:'${param.start}'//当前页数
});
</script>