getProductByKeywordCategory的问题
来源:3-6 nginx反向代理服务器安装与配置实操(windows)
阿满___最帅
2020-06-07
@Override
public ServerResponse<PageInfo> getProductByKeywordCategory(String keyword , Integer categoryId , int pageNum , int pageSize , String orderBy){
if(StringUtils.isBlank(keyword) && categoryId == null){
return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUEMENT.getCode() , ResponseCode.ILLEGAL_ARGUEMENT.getDesc());
}
//如果查询的是父级产品时,要呈现出子级别产品
List<Integer> categoryList = new ArrayList<>();
if(categoryId != null){
Category category = categoryMapper.selectByPrimaryKey(categoryId);
if(category == null && StringUtils.isNotBlank(keyword)){
//没有该分类,并且没有关键字,但是没有错误
PageHelper.startPage(pageNum , pageSize);
List<ProductDetailVo> productDetailVoList = newArrayList();
//传入空的list
PageInfo pageInfo = new PageInfo(productDetailVoList);
return ServerResponse.createBySuccess(pageInfo);
}
categoryList = iCategoryService.selectCategoryAndChildrenById(category.getId()).getData();
}
if(StringUtils.isNotBlank(keyword)){
keyword = new StringBuilder().append("%").append(keyword).append("%").toString();
}
PageHelper.startPage(pageNum , pageSize);
//排序处理
if(StringUtils.isNotBlank(orderBy)){
if(Const.ProductListOrderBy.PRICE_ASC_DESC.contains(orderBy)){
//根据"_"符号,将orderByArray分割
String[] orderByArray = orderBy.split("_");
PageHelper.orderBy(orderByArray[0] + " " + orderByArray[1]);
}
}
List<Product> productList = productMapper.selectByNameAndCategoryIds(StringUtils.isBlank(keyword) ? null : keyword, categoryList.size() == 0 ? null : categoryList);
System.out.println(productList);
List<ProductListVo> productDetailVoList = Lists.newArrayList();
for(Product product : productList){
ProductListVo productListVo = assembleProductListVo(product);
productDetailVoList.add(productListVo);
}
System.out.println(productDetailVoList);
PageInfo pageInfo = new PageInfo(productList);
pageInfo.setList(productDetailVoList);
return ServerResponse.createBySuccess(pageInfo);
}
老师我这个查出来怎么productDetailVoList一直为空
这个输出的是productList,只有page的,也没有显示数据库中查到的东西
Page{count=true, pageNum=0, pageSize=10, startRow=0, endRow=0, total=3, pages=1, countSignal=true, orderBy='price desc',
orderByOnly=false, reasonable=false, pageSizeZero=false}
~~~xml
<select id="selectByNameAndCategoryIds" resultMap="BaseResultMap" parameterType="map">
SELECT
<include refid="Base_Column_List"></include>
from mmall_product
where status = 1
<if test="productName != null">
and name like #{productName}
</if>
<if test="categoryIdList != null" >
and category_id in
<foreach item="item" index="index" open="(" separator="," close=")" collection="categoryIdList">
#{item}
</foreach>
</if>
</select>
写回答
2回答
-
阿满___最帅
提问者
2020-06-08
查询语句没问题呀
00 -
geelylucky
2020-06-08
同学,你把这个sql语句拿出来,把相关参数填好,放到mysql中去执行一下看看。
032020-06-09
相似问题
线程安全问题
回答 2
artifacts配置问题
回答 2