1.spring boot使用pagehelper的时候mybatis显示报空指针异常
2.如果不加分页就没有这个错误,但是查出来的就不是分页的效果
3.别的接口也是调用这个分页方法,但是能够正常分页
代码如下
//查询所有用户的controller层
@RequestMapping(value = "/tapapi/system/users/get", method = RequestMethod.GET)
public Message query(User user, HttpServletRequest request) {
setPageInfo(request, user); // 对http请求结果进行分页
List<User> list = userService.selectList(user);
return getDataMessage(list);
}
//这个是查询所有用户的service层
@Override
public List<User> selectList(User user) {
List<User> list = userDao.selectUserList(user);
for (User user1:list){
Role role =roleDao.selectByPrimaryKey(user1.getRoleId().intValue());
user1.setRoleName(role.getRoleName());
}
return list;
}
//mybatis
<select id="selectUserList" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from sys_user
<where>
<if test="searchValue != null and searchValue != ''">AND userName like concat('%',# {searchValue},'%') </if>
<if test="status !=null ">And status = #{status}</if>
<if test="userName !=null and userName!='' ">And userName = #{userName}</if>
</where>
</select>
//分页的方法
/**
* 设置请求分页数据
*/
protected void setPageInfo(HttpServletRequest request,Object obj) {
PageDomain page = (PageDomain) obj;
analyzeRequest(request,page);
if (page.getPage()!=null && page.getCount()!=null) {//angularJs
PageHelper.startPage(page.getPage(), page.getCount(), page.getOrderBy());
}
}
/**
* @Title: analyzeRequest
* @Description: 解析请求参数中的Filter 和 sort
* @param request HttpServletRequest
* @param page PageDomain
*/
private void analyzeRequest(HttpServletRequest request, PageDomain page) {
String searchValue = request.getParameter("searchValue");
if(StringUtils.isNotBlank(searchValue)){
try {
page.setSearchValue(URLDecoder.decode(searchValue,"utf-8"));
} catch (UnsupportedEncodingException e) {
e.getStackTrace();
}
}
//解析sort
Map<String, String[]> paramMap = request.getParameterMap();
for(Map.Entry<String, String[]> entity:paramMap.entrySet()){
String key = entity.getKey();
if(key.startsWith("sorting")){
int start = key.indexOf('[');
int end = key.indexOf(']');
page.setSort(key.substring(start+1, end));
page.setIsAsc(entity.getValue()[0]);
break;
}
}
}
下面是报错的截图,这里的com.vcmy.dao.UserDao.selectUserList_COUNT好像是上面的pagehelper执行的sql语言不是我写的,问题是别的接口也是用这种方法可以正常查询出来