后端编写分页查询

develop
ddyd 2 weeks ago
parent eebdef758b
commit ab7edb4ee6

@ -34,7 +34,7 @@ public class AttrController {
/**
*
*/
@RequestMapping("/list")
@RequestMapping("/list/{catelogId}")
//@RequiresPermissions("product:attr:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = attrService.queryPage(params);

@ -34,11 +34,13 @@ public class AttrGroupController {
/**
*
*/
@RequestMapping("/list")
@RequestMapping("/list/{catelogId}")
//@RequiresPermissions("product:attrgroup:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = attrGroupService.queryPage(params);
public R list(@RequestParam Map<String, Object> params,
@PathVariable("catelogId") Long catelogId){
//PageUtils page = attrGroupService.queryPage(params);
PageUtils page = attrGroupService.querypage(params, catelogId;
return R.ok().put("page", page);
}

@ -16,5 +16,7 @@ import java.util.Map;
public interface AttrGroupService extends IService<AttrGroupEntity> {
PageUtils queryPage(Map<String, Object> params);
PageUtils querypage(Map<String, Object> params, Long catelogId);
}

@ -16,5 +16,6 @@ import java.util.Map;
public interface AttrService extends IService<AttrEntity> {
PageUtils queryPage(Map<String, Object> params);
}

@ -1,5 +1,6 @@
package com.bookstore.bookmall.product.service.impl;
import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -26,4 +27,29 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEnt
return new PageUtils(page);
}
@Override
public PageUtils querypage(Map<String, Object> params, Long catelogId) {
if (catelogId == 0) {
IPage<AttrGroupEntity> page = this.page(
new Query<AttrGroupEntity>().getPage(params),
new QueryWrapper<AttrGroupEntity>());
return new PageUtils(page);
}else {
//多字段模糊检索
//select * from pms_attr_group where catelog_id=? and (attr_group_id=key or attr_group_name like %key% or descript=key)
String key = (String) params.get("key");
//数据库chax
QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId);
if (!StringUtil.isNullOrEmpty(key)){
//将wrapper构造以后用这个查询
wrapper.and((obj)->{
obj.eq("attr_group_id",key).or().like("attr_group_name", key)
});
}
IPage<AttrGroupEntity> page = this.page(
new Query<AttrGroupEntity>().getPage(params), wrapper);
return new PageUtils(page)
}
}
}

@ -17,7 +17,7 @@ import com.bookstore.bookmall.product.service.AttrService;
public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements AttrService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
public PageUtils queryPage(Map<String, Object> params, Long catelogId) {
IPage<AttrEntity> page = this.page(
new Query<AttrEntity>().getPage(params),
new QueryWrapper<AttrEntity>()

Loading…
Cancel
Save