![](https://img-blog.csdnimg.cn/img_convert/7e31ed3a11d1de1acbb16494935dbf2d.png)
![](https://img-blog.csdnimg.cn/img_convert/d142c37b343054af0a1cc322182c5900.png)
![](https://img-blog.csdnimg.cn/img_convert/f96174e9165f96f32c04a352aae33e59.png)
@RequestMapping("/list")
//@RequiresPermissions("product:spuinfo:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = spuInfoService.queryPageByCondition(params);
return R.ok().put("page", page);
}
![](https://img-blog.csdnimg.cn/img_convert/82af984758ba472c4bfbce67ed2a7288.png)
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SpuInfoEntity> wrapper = new QueryWrapper<>();
String key = (String) params.get("key");
//因为这里有or所以必须添加一个and让他变成status=1 and (id=1 or spu_name like...)
if(!StringUtils.isEmpty(key)){
wrapper.and((w)->{
w.eq("id",key).or().like("spu_name",key);
});
}
String status = (String) params.get("status");
if(!StringUtils.isEmpty(status)){
wrapper.eq("publish_status",status);
}
String brandId = (String) params.get("brandId");
if(!StringUtils.isEmpty(brandId)){
wrapper.eq("brand_id",brandId);
;
}
//注意这里数据库的字段
String catelogId = (String) params.get("catalogId");
if(!StringUtils.isEmpty(catelogId)){
wrapper.eq("catalog_id",catelogId);
}
IPage<SpuInfoEntity> page = this.page(
new Query<SpuInfoEntity>().getPage(params),wrapper
);
return new PageUtils(page);
}
数据库时间格式化:
![](https://img-blog.csdnimg.cn/img_convert/f05da39c292e09f9de732b5fa3a342c0.png)
spring.jackson
![](https://img-blog.csdnimg.cn/img_convert/15c006f48ccd4fc1651eaba065983930.png)
![](https://img-blog.csdnimg.cn/img_convert/e71eafa7cb01ef713ccd862718a8d689.png)
![](https://img-blog.csdnimg.cn/img_convert/52fa25a4927654b87986b7cb02e2a0ce.png)
![](https://img-blog.csdnimg.cn/img_convert/c32ecace859bd1e5323cdc63b5e5ec7e.png)
@RequestMapping("/list")
//@RequiresPermissions("product:skuinfo:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = skuInfoService.queryPageByCondition(params);
return R.ok().put("page", page);
}
![](https://img-blog.csdnimg.cn/img_convert/3981a61b53c66bc4e1406b54da4a0c67.png)
@Service("skuInfoService")
public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),
new QueryWrapper<SkuInfoEntity>()
);
return new PageUtils(page);
}
@Override
public void saveSkuInfo(SkuInfoEntity skuInfoEntity) {
this.baseMapper.insert(skuInfoEntity);
}
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SkuInfoEntity> wrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if(!StringUtils.isEmpty(key)){
wrapper.and(w -> w.eq("sku_id", key).or().like("sku_name", key));
}
// 三级id没选择不应该拼这个条件 没选应该查询所有
String catelogId = (String) params.get("catelogId");
if(!StringUtils.isEmpty(catelogId) && !"0".equalsIgnoreCase(catelogId)){
wrapper.eq("catalog_id", catelogId);
}
String brandId = (String) params.get("brandId");
if(!StringUtils.isEmpty(brandId) && !"0".equalsIgnoreCase(brandId)){
wrapper.eq("brand_id", brandId);
}
String min = (String) params.get("min");
if(!StringUtils.isEmpty(min)){
// gt : 大于; ge: 大于等于
wrapper.ge("price", min);
}
String max = (String) params.get("max");
if(!StringUtils.isEmpty(max)){
try {
BigDecimal bigDecimal = new BigDecimal(max);
if(bigDecimal.compareTo(new BigDecimal("0")) == 1){
// le: 小于等于
wrapper.le("price", max);
}
} catch (Exception e) {
System.out.println("com.wuyimin.gulimall.product.service.impl.SkuInfoServiceImpl:前端传来非数字字符");
}
}
if(!StringUtils.isEmpty(key)){
}
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),wrapper
);
return new PageUtils(page);
}
}