首先给我们的项目添加需要的xml配置文件
先在显示的主界面的jsp中添加按钮
<tr>
<td colspan="11">
<form action="list" method="post">
<input type="hidden" name="page" id="page">
<input type="text" name="mohu">
<input type="submit" value="查询商品">
</form>
</td>
</tr>
<tr>
<td colspan="11">
<input type="button" value="首页" onclick="fenye(1)">
<input type="button" value="上一页" onclick="fenye(${pg.prevpage})">
<input type="button" value="下一页" onclick="fenye(${pg.nextpage})">
<input type="button" value="末页" onclick="fenye(${pg.countpage})">
</td>
</tr>
function fenye(page){
document.getElementById("page").value=page;
document.forms[0].submit();
}
返回我们的控制层去编写
@RequestMapping(“list”)
public String list(HttpServletRequest request,String page,String mohu) {
mohu=mohu==null?"":mohu;
int count=mapper.count(mohu);
PageUtil pg = new PageUtil(page, 3, count);
pg.setMohu(mohu);
pg.setPagesize(pg.getDangqianye()*3);
List<Er> list=mapper.list(pg);
request.setAttribute("list", list);
request.setAttribute("mohu", mohu);
request.setAttribute("pg", pg);
return "list";
}
接入到操作层去
@Select(“select * from er where ename like concat(’%’,#{mohu},’%’) limit #{shoucanshu},#{pagesize}”)
List list(PageUtil pg);
@Select(“select count(*) from er where ename like concat(’%’,#{mohu},’%’)”)
int count(String mohu);