突然发现以前这样写分页查询有点麻烦了 使用的是 MP
@PostMapping("/page")
@ApiModelProperty("购物车分页查询")
public Result<Object> page(@RequestBody CartInfoQueryDto dto){
return Result.ok(cartInfoService.queryCartInfo(dto));
}
@Override
public IPage<CartInfoPageVo> queryCartInfo(CartInfoQueryDto dto){
IPage<CartInfoPageVo> page = new Page<CartInfoPageVo>(dto.getPageNum(), dto.getPageSize());
return baseMapper.queryCartInfo(page, dto);
}
public interface CartInfoMapper extends BaseMapper<CartInfo> {
IPage<CartInfoPageVo> queryCartInfo(IPage<CartInfoPageVo> page, @Param("dto")CartInfoQueryDto dto);
}
<select id="queryCartInfo" resultType="com.yq.ylmall.vo.cart.CartInfoPageVo">
SELECT user_id as userId, category_id as categoryId, sku_type as skuType, sku_name as skuName, sku_id as skuId,
cart_price as cartPrice, sku_num as skuNum, per_limit as perLimit, img_url as imgUrl, is_checked as isChecked,
status,ware_id as wareId from cart_info
<if test="dto.userId != null and dto.userId != ''">
AND user_id like concat('%'#{dto.userId},'%')
</if>
<if test="dto.categoryId != null and dto.categoryId != ''">
AND category_id like concat('%'#{dto.categoryId},'%')
</if>
<if test="dto.skuType != null and dto.skuType != ''">
AND sku_type like concat('%'#{dto.skuType},'%')
</if>
<if test="dto.skuName != null and dto.skuName != ''">
AND sku_name like concat('%'#{dto.skuName},'%')
</if>
<if test="dto.skuId != null and dto.skuId != ''">
AND sku_id like concat('%'#{dto.skuId},'%')
</if>
<if test="dto.cartPrice != null and dto.cartPrice != ''">
AND cart_price like concat('%'#{dto.cartPrice},'%')
</if>
<if test="dto.skuNum != null and dto.skuNum != ''">
AND sku_num like concat('%'#{dto.skuNum},'%')
</if>
<if test="dto.perLimit != null and dto.perLimit != ''">
AND per_limit like concat('%'#{dto.perLimit},'%')
</if>
<if test="dto.wareId != null and dto.wareId != ''">
AND ware_id like concat('%'#{dto.wareId},'%')
</if>
where is_deleted = 0
ORDER BY id DESC
</select>
其实大可以在业务层代码里面将dto 里面的属性全部取出来然后判断判空,决定是不是要拼接到lambdawrapper里面进行条件查询