增加mybatis代码生成功能

This commit is contained in:
2025-07-08 00:11:24 +08:00
parent 8b656907a3
commit 23537aa318
6 changed files with 55 additions and 63 deletions

39
pom.xml
View File

@ -181,17 +181,16 @@
<version>2.11.1</version> <!-- 可根据需要选择版本 --> <version>2.11.1</version> <!-- 可根据需要选择版本 -->
</dependency> </dependency>
<!-- Springdoc OpenAPI UI -->
<dependency> <dependency>
<groupId>org.springdoc</groupId> <groupId>io.springfox</groupId>
<artifactId>springdoc-openapi-ui</artifactId> <artifactId>springfox-swagger2</artifactId>
<version>1.6.14</version> <!-- 支持 Java 8 的最新版本 --> <version>2.9.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.webjars</groupId> <groupId>io.springfox</groupId>
<artifactId>swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>
<version>4.15.5</version> <version>2.9.2</version>
</dependency> </dependency>
<!-- JAXB API (Java 8 兼容) --> <!-- JAXB API (Java 8 兼容) -->
@ -249,32 +248,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>4.15.5</version>
<type>jar</type>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<includes>META-INF/resources/**</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>

View File

@ -1,16 +0,0 @@
package com.sczx.store.config;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
//@Configuration
public class SpringDocConfig {
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("sczx-service")
.packagesToScan("com.sczx.app.controller")
.build();
}
}

View File

@ -0,0 +1,35 @@
package com.sczx.store.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.sczx.store.controller")) // 修改为你的 controller 包路径
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("门店服务接口文档")
.description("sczx_store门店服务接口文档文档")
.version("1.0")
.build();
}
}

View File

@ -13,8 +13,8 @@ import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@Configuration //@Configuration
@EnableWebMvc //@EnableWebMvc
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
@Override @Override

View File

@ -68,11 +68,11 @@ hystrix:
thread: thread:
timeoutInMilliseconds: 10000 # 默认熔断超时时间 timeoutInMilliseconds: 10000 # 默认熔断超时时间
springdoc: #springdoc:
swagger-ui: # swagger-ui:
url: /v3/api-docs # url: /v3/api-docs
path: /doc.html # path: /doc.html
packages-to-scan: com.sczx.store.controller # 替换为你的 controller 包路径 # packages-to-scan: com.sczx.store.controller # 替换为你的 controller 包路径
mybatis-plus: mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml mapper-locations: classpath*:mapper/**/*.xml
@ -81,6 +81,6 @@ mybatis-plus:
mapUnderscoreToCamelCase: true mapUnderscoreToCamelCase: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 控制台打印 SQL调试用 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 控制台打印 SQL调试用
#auth: auth:
# secret-key: his-is-a-very-long-and-secure-secret-key-for-jwt-signing-please-dont-use-short-keys secret-key: his-is-a-very-long-and-secure-secret-key-for-jwt-signing-please-dont-use-short-keys
# token-expiration: 86400000 # 24小时 token-expiration: 86400000 # 24小时

View File

@ -11,9 +11,9 @@ import java.util.Collections;
public class CodeGenerator { public class CodeGenerator {
private static final String parentPackage = "com.sczx.store"; private static final String parentPackage = "com.sczx.store";
private static final String jdbcUrl = "jdbc:mysql://115.190.8.52:3306/sczx?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&useSSL=false&serverTimezone=Asia/Shanghai"; private static final String jdbcUrl = "jdbc:mysql://115.190.8.52:3306/sczx?useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&useSSL=false&serverTimezone=Asia/Shanghai";
private static final String username = "sczx_user"; private static final String username = "sczx_user";
private static final String password = "Sczx123"; private static final String password = "Sczx123@";
private static final String author = "zhangli"; private static final String author = "zhangli";
public static void main(String[] args) { public static void main(String[] args) {
DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig.Builder(jdbcUrl, username, password); DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig.Builder(jdbcUrl, username, password);
@ -25,12 +25,12 @@ public class CodeGenerator {
.dateType(DateType.TIME_PACK).commentDate("yyyy-MM-dd HH:mm:ss") .dateType(DateType.TIME_PACK).commentDate("yyyy-MM-dd HH:mm:ss")
.fileOverride()) .fileOverride())
// 包配置 // 包配置
.packageConfig(builder -> builder.parent(parentPackage).entity("po.base").service("repository.base").serviceImpl("repository.base.impl").xml("") .packageConfig(builder -> builder.parent(parentPackage).entity("po.base").service("repository.base").serviceImpl("repository.impl.base").xml("")
.mapper("mapper.base").pathInfo(Collections.singletonMap(OutputFile.mapperXml, System.getProperty("user.dir") + "/src/main/resources/mapper/base"))) .mapper("mapper.base").pathInfo(Collections.singletonMap(OutputFile.mapperXml, System.getProperty("user.dir") + "/src/main/resources/mapper/base")))
// 策略配置 // 策略配置
.strategyConfig((scanner, builder) -> builder.addInclude(scanner.apply("请输入表名:")) .strategyConfig((scanner, builder) -> builder.addInclude(scanner.apply("请输入表名:"))
.addTablePrefix("t_"/*,"cd_"*/)//可支持多个,按逗号分隔 .addTablePrefix("zc_"/*,"zd_"*/)//可支持多个,按逗号分隔
.entityBuilder().formatFileName("%sPO").enableLombok() .entityBuilder().formatFileName("%sPO").enableLombok()
.mapperBuilder().formatMapperFileName("%sMapper").formatXmlFileName("%sMapper") .mapperBuilder().formatMapperFileName("%sMapper").formatXmlFileName("%sMapper")
.controllerBuilder().formatFileName("%sController").enableRestStyle() .controllerBuilder().formatFileName("%sController").enableRestStyle()