Commit a486d4fa0bc29e7114d07e0ea7a20f8de97f3b1b
Committed by
GitHub
Merge pull request #1226 from dadiyang/fix/product-spu-app-page-sort-nullsafe
[BUG] 商品:C 端商品列表只传 sortField 不传 sortAsc 恒 500——Boolean 对 null 拆箱
Showing
1 changed file
with
5 additions
and
3 deletions
yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java
| ... | ... | @@ -76,14 +76,16 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { |
| 76 | 76 | query.eq(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus()); |
| 77 | 77 | |
| 78 | 78 | // 排序逻辑 |
| 79 | + // 排序方式(sortAsc)可能缺省或显式传 null(合法但参数不完整的组合),缺省按升序处理,避免拆箱 null 崩 500 | |
| 80 | + Boolean sortAsc = pageReqVO.getSortAsc() != null ? pageReqVO.getSortAsc() : Boolean.TRUE; | |
| 79 | 81 | if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_SALES_COUNT)) { |
| 80 | 82 | query.last(String.format(" ORDER BY (sales_count + virtual_sales_count) %s, sort DESC, id DESC", |
| 81 | - pageReqVO.getSortAsc() ? "ASC" : "DESC")); | |
| 83 | + sortAsc ? "ASC" : "DESC")); | |
| 82 | 84 | } else if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_PRICE)) { |
| 83 | - query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getPrice) | |
| 85 | + query.orderBy(true, sortAsc, ProductSpuDO::getPrice) | |
| 84 | 86 | .orderByDesc(ProductSpuDO::getSort).orderByDesc(ProductSpuDO::getId); |
| 85 | 87 | } else if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_CREATE_TIME)) { |
| 86 | - query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getCreateTime) | |
| 88 | + query.orderBy(true, sortAsc, ProductSpuDO::getCreateTime) | |
| 87 | 89 | .orderByDesc(ProductSpuDO::getSort).orderByDesc(ProductSpuDO::getId); |
| 88 | 90 | } else { |
| 89 | 91 | query.orderByDesc(ProductSpuDO::getSort).orderByDesc(ProductSpuDO::getId); | ... | ... |