From 035fa8315fcb2418084afa4b05b81f0461bfc28d Mon Sep 17 00:00:00 2001 From: ddyd <2073699128@qq.com> Date: Wed, 20 Aug 2025 22:16:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=90=8E=E5=8F=B0=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=88=86=E7=BB=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/config/MybatisConfig.java | 14 ++++++++++- .../product/controller/BrandController.java | 2 ++ .../CategoryBrandRelationController.java | 20 ++++++++++----- .../service/CategoryBrandRelationService.java | 2 ++ .../service/impl/AttrGroupServiceImpl.java | 23 +++++++++-------- .../service/impl/BrandServiceImpl.java | 12 +++++++-- .../CategoryBrandRelationServiceImpl.java | 25 +++++++++++++++++++ 7 files changed, 78 insertions(+), 20 deletions(-) diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/config/MybatisConfig.java b/book-product/src/main/java/com/bookstore/bookmall/product/config/MybatisConfig.java index bc63ab4..bdd7c2a 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/config/MybatisConfig.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/config/MybatisConfig.java @@ -1,11 +1,23 @@ package com.bookstore.bookmall.product.config; +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration @EnableTransactionManagement -@MapperScan("com.baomidou.cloud.service.*.mapper") +@MapperScan("com.bookstore.bookmall.product.dao") public class MybatisConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加 + // 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType + return interceptor; + } } diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/controller/BrandController.java b/book-product/src/main/java/com/bookstore/bookmall/product/controller/BrandController.java index 9d86ed9..54183da 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/controller/BrandController.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/controller/BrandController.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; +import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil; import com.bookstore.common.valid.AddGroup; import com.bookstore.common.valid.AddShowStatusGroup; import org.springframework.beans.factory.annotation.Autowired; @@ -43,6 +44,7 @@ public class BrandController { @RequestMapping("/list") //@RequiresPermissions("product:brand:list") public R list(@RequestParam Map params){ + PageUtils page = brandService.queryPage(params); return R.ok().put("page", page); diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/controller/CategoryBrandRelationController.java b/book-product/src/main/java/com/bookstore/bookmall/product/controller/CategoryBrandRelationController.java index 539de0e..3291fb4 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/controller/CategoryBrandRelationController.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/controller/CategoryBrandRelationController.java @@ -1,15 +1,13 @@ package com.bookstore.bookmall.product.controller; import java.util.Arrays; +import java.util.List; import java.util.Map; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.bookstore.bookmall.product.entity.CategoryBrandRelationEntity; import com.bookstore.bookmall.product.service.CategoryBrandRelationService; @@ -42,6 +40,16 @@ public class CategoryBrandRelationController { return R.ok().put("page", page); } + //@RequestMapping("/catelog/list") + //@RequiresPermissions("product:categorybrandrelation:list") + @GetMapping("/catelog/list") + public R cateloglist(@RequestParam("brandId") Long brandId){ + List data = categoryBrandRelationService.list( + new QueryWrapper().eq("brand_id", brandId)); + + return R.ok().put("data", data); + } + /** * 信息 @@ -60,7 +68,7 @@ public class CategoryBrandRelationController { @RequestMapping("/save") //@RequiresPermissions("product:categorybrandrelation:save") public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){ - categoryBrandRelationService.save(categoryBrandRelation); + categoryBrandRelationService.saveDetail(categoryBrandRelation); return R.ok(); } diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/service/CategoryBrandRelationService.java b/book-product/src/main/java/com/bookstore/bookmall/product/service/CategoryBrandRelationService.java index 797ec94..c3c58f5 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/service/CategoryBrandRelationService.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/service/CategoryBrandRelationService.java @@ -16,5 +16,7 @@ import java.util.Map; public interface CategoryBrandRelationService extends IService { PageUtils queryPage(Map params); + + void saveDetail(CategoryBrandRelationEntity categoryBrandRelation); } diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/AttrGroupServiceImpl.java b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/AttrGroupServiceImpl.java index 7baa82d..3187457 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/AttrGroupServiceImpl.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/AttrGroupServiceImpl.java @@ -29,23 +29,24 @@ public class AttrGroupServiceImpl extends ServiceImpl params, Long catelogId) { + //多字段模糊检索 + //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"); + //数据库查询 QueryWrapper + QueryWrapper wrapper = new QueryWrapper(); + if (!StringUtil.isNullOrEmpty(key)){ + //将wrapper构造以后用这个查询 + wrapper.and((obj)->{ + obj.eq("attr_group_id",key).or().like("attr_group_name", key); + }); + } if (catelogId == 0) { IPage page = this.page( new Query().getPage(params), new QueryWrapper()); 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"); - //数据库查询 QueryWrapper - QueryWrapper wrapper = new QueryWrapper().eq("catelog_id", catelogId); - if (!StringUtil.isNullOrEmpty(key)){ - //将wrapper构造以后用这个查询 - wrapper.and((obj)->{ - obj.eq("attr_group_id",key).or().like("attr_group_name", key); - }); - } + wrapper.eq("catelog_id", catelogId); IPage page = this.page( new Query().getPage(params), wrapper); return new PageUtils(page); diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/BrandServiceImpl.java b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/BrandServiceImpl.java index 1934de7..66c537e 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/BrandServiceImpl.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/BrandServiceImpl.java @@ -1,5 +1,6 @@ package com.bookstore.bookmall.product.service.impl; +import com.mysql.cj.util.StringUtils; import org.springframework.stereotype.Service; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -18,9 +19,16 @@ public class BrandServiceImpl extends ServiceImpl impleme @Override public PageUtils queryPage(Map params) { + String key = (String)params.get("key"); + + QueryWrapper wrapper = new QueryWrapper(); + + if (!StringUtils.isNullOrEmpty(key)) { + wrapper.eq("brand_id", key).or().like("name", key); + } + IPage page = this.page( - new Query().getPage(params), - new QueryWrapper() + new Query().getPage(params), wrapper ); return new PageUtils(page); diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/CategoryBrandRelationServiceImpl.java b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/CategoryBrandRelationServiceImpl.java index 15579e6..92e2616 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/CategoryBrandRelationServiceImpl.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/CategoryBrandRelationServiceImpl.java @@ -1,5 +1,10 @@ package com.bookstore.bookmall.product.service.impl; +import com.bookstore.bookmall.product.dao.BrandDao; +import com.bookstore.bookmall.product.dao.CategoryDao; +import com.bookstore.bookmall.product.entity.BrandEntity; +import com.bookstore.bookmall.product.entity.CategoryEntity; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -16,6 +21,11 @@ import com.bookstore.bookmall.product.service.CategoryBrandRelationService; @Service("categoryBrandRelationService") public class CategoryBrandRelationServiceImpl extends ServiceImpl implements CategoryBrandRelationService { + @Autowired + BrandDao brandDao; + @Autowired + CategoryDao categoryDao; + @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -26,4 +36,19 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl