按id搜索返回为空
来源:8-5 后台商品搜索功能开发

wendy_z
2018-01-15
老师,我在自测的时候,按照id来搜索的话,返回为空,如果不填写productName和productId那么返回结果也为空,不应该是返回所有嘛,我对照了老师的代码就是这样写的,没找到原因呢??
xml文件:
<select id="selectProductByNameAndId" resultMap="BaseResultMap" parameterType="map">
SELECT
<include refid="Base_Column_List"/>
from mmall_product
<where>
<if test="productName !=null">
and name like #{productName}
</if>
<if test="productId !=null">
and id=#{productId}
</if>
</where>
</select>
controller文件:
@RequestMapping(value = "search.do",method = RequestMethod.POST)
@ResponseBody
public ServerResponse search(HttpSession session,String productName,Integer productId,@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
User user = (User) session.getAttribute(Const.CURRENT_USER);
if (user ==null){
return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),ResponseCode.ILLEGAL_ARGUMENT.getDesc());
}
if (iUserService.checkAdminRole(user).isSuccess()){
return iProductService.getSearchResult(productName,productId,pageNum,pageSize);
}
返回结果:
{
"status": 0,
"data":{
"pageNum": 1,
"pageSize": 20,
"size": 0,
"orderBy": null,
"startRow": 0,
"endRow": 0,
"total": 0,
"pages": 0,
"list":[
],
"firstPage": 0,
"prePage": 0,
"nextPage": 0,
"lastPage": 0,
"isFirstPage": true,
"isLastPage": false,
"hasPreviousPage": false,
"hasNextPage": false,
"navigatePages": 8,
"navigatepageNums":[]
}
}
3回答
-
wendy_z
提问者
2018-01-22
不输入productName和productId,或者只输入productId的话,size怎么都是0呢,我看了我的sql语句跟老师的是一样的呀,但是根据debug结果来看,感觉有点问题,不输入productId的话,默认的productId值就是null,然后sql语句写的是如果product !=null才执行id=#{productId};但是为什么我输入productId,还是返回size为0呢?
如果输入productId,debug结果为:
00 -
Geely
2018-01-20
你好,同学这个主要看service的实现,可以打一个断点看一下。这样还能学习一下debug,建议实操一下。以后工作这种场景会很多。
课程项目思维导图及线上环境、测试环境、部署linux和windows等解答
http://www.imooc.com/article/20193
部署环境的话 ,建议看下文章最后一小段哟~首先跟着课程阿里云部署那个章节过一遍,可以先不跟着操作,做到心里有数,环境部署都做了什么。
尽快进入咱们QQ群哟~~进群方法下面思维导图那个帖子有。非常详细
课程项目思维导图及线上环境、测试环境、部署linux和windows等解答
http://www.imooc.com/article/20193
【重点】问答区常见问题整理
http://www.imooc.com/article/18998
课程项目QQ群分享手记
http://www.imooc.com/article/19094
找工作的季节之简历及找工作的分享
http://www.imooc.com/article/19998
项目环境、vsftpd、linux、mysql等各种配置、软件下载
http://learning.happymmall.com
mybatis-plugin插件安装
http://coding.imooc.com/learn/questiondetail/36007.html00 -
星辰Iron
2018-01-15
你好同学,在idea里面进入DEBUG模式打几个断点调试一下看看前端的参数是否正确传递到后台了,把idea控制台里面的日志信息也贴上看看。
042018-01-26