@RequestMapping("mohu")
public String mohuchaxun(@RequestParam(value="pn",defaultValue="1")Integer pn,Model model,books bk){
//从第一条开始 每页查询五条数据
PageHelper.startPage(pn, 3);
List users = userService.mohu(bk);
System.out.println("测试集合有没有获取到数据"+bk.getBookuser());
System.out.println("大小"+users.size());
//将用户信息放入PageInfo对象里
PageInfo page1 = new PageInfo(users,7);
model.addAttribute("pageInfo2", page1);
return "mohu";
}
-----------------------------------------------------------------controller
<select id="mohu" parameterType="books" resultType="books">
select * from
books where bookuser LIKE '%' #{bookuser} '%'
</select>
-------------------------------------------------------------------dao.xml
<c:forEach items="${pageInfo2.list }" var="user">
<tr>
<td>${user.bid}</td>
<td>${user.bookuser }</td>
<td>${user.booktype }</td>
<td><img src="${user.bookimg}" width="200" height="100" ></td>
<!--
<td><img src="${user.bookimg}" width="200" height="300" ></td>
-->
<!-- <td><a class="edit">编辑</a> <a
class="delete">删除</a></td> -->
</tr>
</c:forEach>
</table>
</div>
</div>
<hr style="height:1px;border:none;border-top:1px solid #ccc;" />
<!-- 分页导航栏 -->
<!-- 分页信息 -->
<div class="row">
<!-- 分页文字信息,其中分页信息都封装在pageInfo中 -->
<div class="col-md-6">
当前第:${pageInfo2.pageNum}页,总共:${pageInfo2.pages}页,总共:${pageInfo2.total}条记录
</div>
<!-- 分页条 -->
<div class="col-md-6">
<nav aria-label="Page navigation">
<ul class="hvtulli" style="list-style-type:none">
<li><a href="${path}/user/mohu?pn=1">首页</a></li>
<c:if test="${pageInfo2.hasPreviousPage }">
<li>
<a href="${path}/user/mohu?pn=${pageInfo2.pageNum-1}" aria-label="Previous">
<span aria-hidden="true">上一页</span>
</a>
</li>
</c:if>
<c:forEach items="${pageInfo2.navigatepageNums }" var="page_Num">
<c:if test="${page_Num == pageInfo2.pageNum }">
<li class="active"><a href="#">${ page_Num}</a></li>
</c:if>
<c:if test="${page_Num != pageInfo2.pageNum }">
<li><a href="${path}/user/mohu?pn=${ page_Num}">${ page_Num}</a></li>
</c:if>
</c:forEach>
<c:if test="${pageInfo2.hasNextPage }"><a href="${path}/user/mohu?pn=${pageInfo2.pageNum+1}" aria-label="Next">下一页
</a>
</c:if>
<a href="${path}/user/mohu?pn=${pageInfo2.pages}">末页</a>
-----------------------------------------------------------jsp
普通的查询这样都可以做到。 但是这个模糊查询,点击首页或者末页就会报错,
Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null '%') tmp_count' at line 2
The error may exist in com/ssm/dao/Userdao.xml
The error may involve com.ssm.dao.Userdao.mohu-Inline
The error occurred while setting parameters
SQL: select count(0) from (select * from books where bookuser LIKE '%' ? '%') tmp_count
知道是sql的错误, 请大神帮我看看怎么办。 我是初学者。