電商項目——初識電商——第一章——上篇
電商項目——分布式基礎概念和電商項目微服務架構圖,劃分圖的詳解——第二章——上篇
電商項目——電商項目的虛拟機環境搭建_VirtualBox,Vagrant——第三章——上篇
電商項目——Linux虛拟機中安裝docker,mysql,redis_VirtualBox——第四章——上篇
電商項目——電商項目的環境搭建_開發工具&環境搭建——第五章——上篇
電商項目——快速開發人人開源搭建背景管理系統&代碼生成器逆向工程搭建——第六章——上篇
電商項目——分布式元件(SpringCloud Alibaba,SpringCloud)——第七章——上篇
電商項目——前端基礎——第八章——上篇
電商項目——商品服務-API-三級分類——第九章——上篇
電商項目——商品服務-API-品牌管理——第十章——上篇
電商項目——商品服務-API-屬性分組——第十一章——上篇
電商項目——商品服務-API-品牌管理——第十二章——上篇
電商項目——商品服務-API-平台屬性——第十三章——上篇
電商項目——商品服務-API-新增商品——第十四章——上篇
電商項目——商品服務-API-商品管理——第十五章——上篇
電商項目——商品服務-API-倉庫管理——第十六章——上篇
文章目錄
- 1:SPU檢索
- 2:SKU檢索
1:SPU檢索
SpuInfoController
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
@Autowired
private SpuInfoService spuInfoService;
/**
* 清單
*/
@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);
}
SpuInfoServiceImpl
/**
* spu檢索
* {
page: 1,//目前頁碼
limit: 10,//每頁記錄數
sidx: 'id',//排序字段
order: 'asc/desc',//排序方式
key: '華為',//檢索關鍵字
catelogId: 6,//三級分類id
brandId: 1,//品牌id
status: 0,//商品狀态
}
* @param params
* @return
*/
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SpuInfoEntity> queryWrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)){
queryWrapper.and(w->{
w.eq("id",key).or().like("spu_name",key);
});
}
//上面的 queryWrapper.and代表如下意思
//status=1 and (id=1 or spu_name like xxx)
String catelogId = (String) params.get("catelogId");
if (!StringUtils.isEmpty(catelogId)){
queryWrapper.eq("catalog_id",catelogId);
}
String brandId = (String) params.get("brandId");
if (!StringUtils.isEmpty(brandId)){
queryWrapper.eq("brand_id",brandId);
}
String status = (String) params.get("status");
if (!StringUtils.isEmpty(status)){
queryWrapper.eq("publish_status",status);
}
IPage<SpuInfoEntity> page = this.page(
new Query<SpuInfoEntity>().getPage(params),queryWrapper
);
return new PageUtils(page);
}
#指定化的時間規格
jackson:
data-format: yyyy-MM-dd HH:mm::ss
2:SKU檢索
SkuInfoController
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
@Autowired
private SkuInfoService skuInfoService;
/**
* 清單
*/
@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);
}
SkuInfoServiceImpl
/**
* sku檢索
* @param params
* @return
* {
page: 1,//目前頁碼
limit: 10,//每頁記錄數
sidx: 'id',//排序字段
order: 'asc/desc',//排序方式
key: '華為',//檢索關鍵字
catelogId: 0,
brandId: 0,
min: 0,
max: 0
}
*/
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<SkuInfoEntity> queryWrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)){
queryWrapper.and(w->{
w.eq("sku_id",key).or().like("sku_name",key);
});
}
//上面的 queryWrapper.and代表如下意思
//status=1 and (id=1 or spu_name like xxx)
String catelogId = (String) params.get("catelogId");
if (!StringUtils.isEmpty(catelogId)){
queryWrapper.eq("catalog_id",catelogId);
}
String brandId = (String) params.get("brandId");
if (!StringUtils.isEmpty(brandId)){
queryWrapper.eq("brand_id",brandId);
}
String min = (String) params.get("min");
if (!StringUtils.isEmpty(min)){
queryWrapper.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){
queryWrapper.le("price",max);
}
}catch (Exception e){
}
}
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),queryWrapper
);
return new PageUtils(page);
}