11.商品服务-spu管理和商品管理



@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);
}

@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); }
数据库时间格式化:

spring.jackson




@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);
}

@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);
}
}

浙公网安备 33010602011771号