添加mybatis
This commit is contained in:
21
pom.xml
21
pom.xml
@ -119,6 +119,27 @@
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- MyBatis Plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.3.1</version> <!-- 支持 Java 8 的稳定版本 -->
|
||||
</dependency>
|
||||
|
||||
<!-- MyBatis Plus Generator (可选:用于生成实体类/DAO/Service) -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- freemarker 模板引擎(配合 MP Generator 使用) -->
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.31</version>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL 驱动 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
|
||||
@ -2,6 +2,7 @@ package com.sczx.app;
|
||||
|
||||
import com.sczx.app.common.constant.SystemConstants;
|
||||
import com.sczx.app.utils.ComputerInfo;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
@ -20,6 +21,7 @@ import java.io.IOException;
|
||||
@EnableFeignClients(basePackages = SystemConstants.FEIGN_CLIENT_BASE_PACKAGE )
|
||||
@EnableTransactionManagement
|
||||
@EnableHystrix
|
||||
@MapperScan("com.sczx.app.mapper") // 扫描 Mapper 接口
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
18
src/main/java/com/sczx/app/config/MyBatisPlusConfig.java
Normal file
18
src/main/java/com/sczx/app/config/MyBatisPlusConfig.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.sczx.app.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MyBatisPlusConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
@ -72,3 +72,10 @@ springdoc:
|
||||
url: /v3/api-docs
|
||||
path: /doc.html
|
||||
packages-to-scan: com.sczx.app.controller # 替换为你的 controller 包路径
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:mapper/**/*.xml
|
||||
type-aliases-package: com.sczx.app.entity # 实体类包路径
|
||||
configuration:
|
||||
mapUnderscoreToCamelCase: true
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 控制台打印 SQL(调试用)
|
||||
|
||||
21
src/test/java/com/sczx/app/service/CodeGenerator.java
Normal file
21
src/test/java/com/sczx/app/service/CodeGenerator.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.sczx.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
|
||||
public class CodeGenerator {
|
||||
public static void main(String[] args) {
|
||||
FastAutoGenerator.create("jdbc:mysql://115.190.8.52:3306/sczx", "sczx_user", "Sczx123@")
|
||||
.globalConfig(builder -> {
|
||||
builder.author("yourname")
|
||||
.outputDir(System.getProperty("user.dir") + "/src/main/java");
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.parent("com.sczx.app")
|
||||
.moduleName("user");
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude("user"); // 表名
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user