diff --git a/mall-common/pom.xml b/mall-common/pom.xml index ce8287b..bb49606 100644 --- a/mall-common/pom.xml +++ b/mall-common/pom.xml @@ -22,7 +22,12 @@ org.springframework.boot spring-boot-starter-web - + + + org.springframework.boot + spring-boot-starter-thymeleaf + + org.projectlombok @@ -48,5 +53,6 @@ com.github.xiaoymin knife4j-openapi3-jakarta-spring-boot-starter + diff --git a/mall-common/src/main/java/com/mall/common/config/Knife4jConfig.java b/mall-common/src/main/java/com/mall/common/config/Knife4jConfig.java index bec6145..5dce28d 100644 --- a/mall-common/src/main/java/com/mall/common/config/Knife4jConfig.java +++ b/mall-common/src/main/java/com/mall/common/config/Knife4jConfig.java @@ -1,5 +1,6 @@ package com.mall.common.config; +import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; @@ -8,12 +9,13 @@ import io.swagger.v3.oas.models.info.License; import lombok.extern.slf4j.Slf4j; import org.springdoc.core.models.GroupedOpenApi; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration -// @EnableKnife4j -// @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.ANY) +@EnableKnife4j +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.ANY) @Slf4j public class Knife4jConfig { @@ -43,4 +45,9 @@ public class Knife4jConfig { public GroupedOpenApi all() { return GroupedOpenApi.builder().group("全部请求接口").pathsToMatch("/api/**").build(); } + + @Bean + public GroupedOpenApi product() { + return GroupedOpenApi.builder().group("商品请求接口").pathsToMatch("/api/product/**").build(); + } } diff --git a/mall-common/src/main/java/com/mall/common/config/MybatisPlusConfig.java b/mall-common/src/main/java/com/mall/common/config/MybatisPlusConfig.java new file mode 100644 index 0000000..451e03e --- /dev/null +++ b/mall-common/src/main/java/com/mall/common/config/MybatisPlusConfig.java @@ -0,0 +1,35 @@ +package com.mall.common.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@EnableTransactionManagement +@Configuration +public class MybatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + // 拦截器 + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + + // 使用分页插件 + PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); + paginationInnerInterceptor.setDbType(DbType.MYSQL); + paginationInnerInterceptor.setMaxLimit(600L); + interceptor.addInnerInterceptor(paginationInnerInterceptor); + + // 乐观锁 + interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); + + // 防止全表删除 + interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor()); + + return interceptor; + } +} diff --git a/mall-product/src/main/java/com/mall/product/MallProductApplication.java b/mall-product/src/main/java/com/mall/product/MallProductApplication.java index 9e634e5..a466b8b 100644 --- a/mall-product/src/main/java/com/mall/product/MallProductApplication.java +++ b/mall-product/src/main/java/com/mall/product/MallProductApplication.java @@ -1,14 +1,11 @@ package com.mall.product; -import com.mall.common.config.Knife4jConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication -@ComponentScan(basePackageClasses = {Knife4jConfig.class}) -@EnableTransactionManagement +@ComponentScan(basePackages = {"com.mall.common", "com.mall.product"}) public class MallProductApplication { public static void main(String[] args) { SpringApplication.run(MallProductApplication.class, args); diff --git a/mall-product/src/main/java/com/mall/product/config/Knife4jConfig.java b/mall-product/src/main/java/com/mall/product/config/Knife4jConfig.java deleted file mode 100644 index b698695..0000000 --- a/mall-product/src/main/java/com/mall/product/config/Knife4jConfig.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.mall.product.config; - -import org.springdoc.core.models.GroupedOpenApi; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class Knife4jConfig { - - @Bean - public GroupedOpenApi product() { - return GroupedOpenApi.builder().group("商品请求接口").pathsToMatch("/api/product/**").build(); - } - -} \ No newline at end of file diff --git a/mall-product/src/main/java/com/mall/product/controller/IndexController.java b/mall-product/src/main/java/com/mall/product/controller/IndexController.java new file mode 100644 index 0000000..b7a545c --- /dev/null +++ b/mall-product/src/main/java/com/mall/product/controller/IndexController.java @@ -0,0 +1,13 @@ +package com.mall.product.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class IndexController { + + @GetMapping + public String index() { + return "index"; + } +} diff --git a/mall-product/src/main/resources/application-dev.yml b/mall-product/src/main/resources/application-dev.yml index 53196f1..33fd13c 100644 --- a/mall-product/src/main/resources/application-dev.yml +++ b/mall-product/src/main/resources/application-dev.yml @@ -1,4 +1,4 @@ -bunny: +datasource: master: host: rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com port: 3306 diff --git a/mall-product/src/main/resources/application.yaml b/mall-product/src/main/resources/application.yaml index 79ab242..9759cb7 100644 --- a/mall-product/src/main/resources/application.yaml +++ b/mall-product/src/main/resources/application.yaml @@ -3,16 +3,16 @@ server: spring: profiles: - active: prod + active: dev application: name: service-product datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.database}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true - username: ${bunny.master.username} - password: ${bunny.master.password} + url: jdbc:mysql://${datasource.master.host}:${datasource.master.port}/${datasource.master.database}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true + username: ${datasource.master.username} + password: ${datasource.master.password} hikari: maximum-pool-size: 20 connection-timeout: 30000 diff --git a/mall-product/src/main/resources/templates/index.html b/mall-product/src/main/resources/templates/index.html new file mode 100644 index 0000000..aaf50ff --- /dev/null +++ b/mall-product/src/main/resources/templates/index.html @@ -0,0 +1,508 @@ + + + + + + 谷粒商城 - 商品模块 + + + + + + + + + +
+
+

商品模块

+

谷粒商城核心模块,提供完整的商品管理、分类、品牌、属性等功能

+ +
+
+ + +
+

功能特性

+
+
+
+ +

商品管理

+

完整的商品CRUD操作,支持多规格商品,商品上下架管理,商品搜索等功能。

+
+
+
+
+ +

分类管理

+

多级商品分类系统,支持树形结构展示,分类属性关联,便于商品归类管理。

+
+
+
+
+ +

品牌管理

+

品牌信息维护,品牌logo上传,品牌与分类关联,品牌商品统计等功能。

+
+
+
+
+
+
+ +

属性管理

+

商品属性与规格管理,支持属性分组,属性与分类关联,SKU生成等功能。

+
+
+
+
+ +

图片管理

+

商品图片上传、删除、排序,支持多图展示,主图设置,图片水印等功能。

+
+
+
+
+ +

数据分析

+

商品销售统计,库存预警,热销商品分析,为运营决策提供数据支持。

+
+
+
+
+ + +
+

热门商品

+
+
+
+ -20% + 商品1 +
+
高端智能手机
+

最新款旗舰手机,6.7英寸AMOLED屏幕

+
+
+ ¥3999 + ¥4999 +
+ +
+
+
+
+
+
+ 商品2 +
+
无线蓝牙耳机
+

主动降噪,30小时续航,Hi-Fi音质

+
+
+ ¥699 +
+ +
+
+
+
+
+
+ -15% + 商品3 +
+
轻薄笔记本电脑
+

13.3英寸,16GB内存,512GB SSD

+
+
+ ¥5999 + ¥6999 +
+ +
+
+
+
+
+
+ 商品4 +
+
智能手表
+

心率监测,血氧检测,50米防水

+
+
+ ¥1299 +
+ +
+
+
+
+
+
+ 浏览更多商品 +
+
+ + +
+

API文档

+
+
+

商品API

+
+

获取商品列表

+

GET /api/product/list

+

参数: page, size, categoryId, brandId, keyword

+
+

获取商品详情

+

GET /api/product/info/{id}

+
+
+
+

分类API

+
+

获取分类树

+

GET /api/category/tree

+
+

获取分类属性

+

GET /api/category/attrs/{catId}

+
+
+
+
+
+

品牌API

+
+

获取品牌列表

+

GET /api/brand/list

+

参数: page, size, keyword

+
+

获取品牌详情

+

GET /api/brand/info/{id}

+
+
+
+

属性API

+
+

获取属性分组

+

GET /api/attrgroup/list/{catId}

+
+

获取分组属性

+

GET /api/attr/list/{groupId}

+
+
+
+
+ 查看完整API文档 +
+
+ + +
+

技术架构

+
+
+
+ Spring +

Spring Boot

+
+
+
+
+ Spring Data +

Spring Data

+
+
+
+
+ Spring Cloud +

Spring Cloud

+
+
+
+
+ MySQL +

MySQL

+
+
+
+
+ Redis +

Redis

+
+
+
+
+ Elasticsearch +

Elasticsearch

+
+
+
+
+ + + + + + + + \ No newline at end of file