整合 mybatis-plus knife4j 完善代码生成器
This commit is contained in:
parent
da0ad38004
commit
3c9e7f0b20
@ -0,0 +1,92 @@
|
||||
package com.yovinchen.train.common.utils;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
|
||||
/**
|
||||
* ClassName: com.yovinchen.train.common.utils.MyBatisPlusGenerator
|
||||
* Package: PACKAGE_NAME
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2024/1/19 15:38
|
||||
*/
|
||||
public class MyBatisPlusGenerator {
|
||||
public static void main(String[] args) {
|
||||
|
||||
//1、配置数据源
|
||||
FastAutoGenerator.create("jdbc:mysql://82.157.68.223:3306/train?serverTimezone=GMT%2B8&useSSL=false", "train", "train")
|
||||
|
||||
//2、全局配置
|
||||
.globalConfig(builder -> {
|
||||
builder.author("yovinchen") // 设置作者名
|
||||
.disableOpenDir() //禁止打开输出目录,默认打开
|
||||
.outputDir("member/src/main/java") //设置输出路径:项目的 java 目录下
|
||||
.enableSwagger() //开启 swagger 模式
|
||||
// .enableKotlin()
|
||||
// .enableSpringdoc()
|
||||
.dateType(DateType.ONLY_DATE) //定义生成的实体类中日期的类型 TIME_PACK=LocalDateTime;ONLY_DATE=Date;
|
||||
.commentDate("yyyy-MM-dd hh:mm:ss"); //注释日期
|
||||
})
|
||||
//3、包配置
|
||||
.packageConfig(builder -> {
|
||||
builder.parent("com.yovinchen.train") // 设置父包名
|
||||
.moduleName("member") //设置模块包名
|
||||
.entity("entity") //pojo 实体类包名
|
||||
.service("service") //Service 包名
|
||||
.serviceImpl("service.impl") // ***ServiceImpl 包名
|
||||
.mapper("mapper") //Mapper 包名
|
||||
.xml("mapper") //Mapper XML 包名
|
||||
.controller("controller"); //Controller 包名
|
||||
// .pathInfo(Collections.singletonMap(OutputFile.xml, "./src/main/resources/mapper"));//配置 mapper.xml 路径信息:项目的 resources 目录下
|
||||
})
|
||||
//4、策略配置
|
||||
.strategyConfig(builder -> {
|
||||
// builder.addInclude("incident_point", "incident_sum", "incident_line", "incident_cause_effect", "graph") // 设置需要生成的数据表名
|
||||
builder.addInclude("member", "passenger") // 设置需要生成的数据表名
|
||||
.addTablePrefix("t_", "c_") // 设置过滤表前缀
|
||||
|
||||
//4.1、实体类策略配置
|
||||
.entityBuilder()
|
||||
.enableLombok() //开启 Lombok
|
||||
.addTableFills()
|
||||
.disableSerialVersionUID() //不实现 Serializable 接口,不生产 SerialVersionUID
|
||||
.logicDeleteColumnName("deleted") //逻辑删除字段名
|
||||
.naming(NamingStrategy.underline_to_camel) //数据库表映射到实体的命名策略:下划线转驼峰命
|
||||
.columnNaming(NamingStrategy.underline_to_camel) //数据库表字段映射到实体的命名策略:下划线转驼峰命
|
||||
.idType(IdType.ASSIGN_ID)
|
||||
|
||||
// .addTableFills(new Column("create_time", FieldFill.INSERT))
|
||||
// .addTableFills(new Property("modifyTime", FieldFill.INSERT_UPDATE))
|
||||
.enableTableFieldAnnotation() // 开启生成实体时生成字段注解
|
||||
.enableFileOverride()
|
||||
|
||||
//4.2、Controller策略配置
|
||||
.controllerBuilder()
|
||||
.formatFileName("%sController") //格式化 Controller 类文件名称,%s进行匹配表名,如 UserController
|
||||
.enableRestStyle() //开启生成 @RestController 控制器
|
||||
// .enableFileOverride()
|
||||
|
||||
//4.3、service 策略配置
|
||||
.serviceBuilder()
|
||||
.formatServiceFileName("%sService") //格式化 service 接口文件名称,%s进行匹配表名,如 UserService
|
||||
.formatServiceImplFileName("%sServiceImpl") //格式化 service 实现类文件名称,%s进行匹配表名,如 UserServiceImpl
|
||||
// .enableFileOverride()
|
||||
|
||||
//4.4、Mapper策略配置
|
||||
.mapperBuilder()
|
||||
.superClass(BaseMapper.class) //设置父类
|
||||
.formatMapperFileName("%sMapper") //格式化 mapper 文件名称
|
||||
.enableMapperAnnotation() //开启 @Mapper 注解
|
||||
// .enableFileOverride()
|
||||
.formatXmlFileName("%sMapper"); //格式化 Xml 文件名称
|
||||
|
||||
|
||||
})
|
||||
//6、执行
|
||||
.execute();
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
server:
|
||||
port: 8000
|
||||
spring:
|
||||
application:
|
||||
name: gateway
|
||||
cloud:
|
||||
gateway:
|
||||
routes:
|
||||
|
@ -23,6 +23,10 @@
|
||||
<artifactId>common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.yovinchen.train.member;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@ -16,6 +17,7 @@ import org.springframework.core.env.Environment;
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@ComponentScan("com.yovinchen")
|
||||
@MapperScan("com.yovinchen.train.member.mapper")
|
||||
public class MemberApplication {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MemberApplication.class);
|
||||
|
||||
|
@ -1,18 +1,32 @@
|
||||
package com.yovinchen.train.member.controller;
|
||||
|
||||
import com.yovinchen.train.member.entity.Member;
|
||||
import com.yovinchen.train.member.service.MemberService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 会员 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:10:59
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/member")
|
||||
public class MemberController {
|
||||
|
||||
@Autowired
|
||||
MemberService memberService;
|
||||
|
||||
@GetMapping("/test")
|
||||
public List<Member> test() {
|
||||
return memberService.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,10 +9,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:10:59
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/passenger")
|
||||
public class PassengerController {
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package com.yovinchen.train.member.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* ClassName: testController
|
||||
* Package: com.yovinchen.train.member.controller
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2024/1/18 17:58
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class testController {
|
||||
@GetMapping("/test")
|
||||
public String count() {
|
||||
return "测试";
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ import lombok.Setter;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:36:29
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -17,7 +17,7 @@ import java.util.Date;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:36:29
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:10:59
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
@Mapper
|
||||
public interface MemberMapper extends BaseMapper<Member> {
|
||||
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:10:59
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
@Mapper
|
||||
public interface PassengerMapper extends BaseMapper<Passenger> {
|
||||
|
@ -9,7 +9,7 @@ import com.yovinchen.train.member.entity.Member;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:10:59
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
public interface MemberService extends IService<Member> {
|
||||
|
||||
|
@ -9,7 +9,7 @@ import com.yovinchen.train.member.entity.Passenger;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:10:59
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
public interface PassengerService extends IService<Passenger> {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.yovinchen.train.member.serviceImpl;
|
||||
package com.yovinchen.train.member.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yovinchen.train.member.entity.Member;
|
||||
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:10:59
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
@Service
|
||||
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {
|
@ -1,4 +1,4 @@
|
||||
package com.yovinchen.train.member.serviceImpl;
|
||||
package com.yovinchen.train.member.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yovinchen.train.member.entity.Passenger;
|
||||
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2024-01-19 04:10:59
|
||||
* @since 2024-01-19 09:53:20
|
||||
*/
|
||||
@Service
|
||||
public class PassengerServiceImpl extends ServiceImpl<PassengerMapper, Passenger> implements PassengerService {
|
@ -7,9 +7,23 @@ spring:
|
||||
name: member
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://82.157.68.223:3306/train?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
|
||||
name: train
|
||||
url: jdbc:mysql://82.157.68.223:3306/train?characterEncoding=utf-8&useSSL=false
|
||||
password: train
|
||||
username: train
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
maximum-pool-size: 15
|
||||
minimum-idle: 5
|
||||
idle-timeout: 30000
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
auto-mapping-behavior: full
|
||||
map-underscore-to-camel-case: true
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
mapper-locations: classpath*:/mapper/**/*.xml # xml路径
|
||||
global-config:
|
||||
banner: false
|
||||
type-aliases-package: com.yovinchen.train.member.entity
|
||||
# springdoc-openapi项目配置
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
|
2
pom.xml
2
pom.xml
@ -23,7 +23,7 @@
|
||||
<java.version>17</java.version>
|
||||
<spring-cloud.version>2022.0.0</spring-cloud.version>
|
||||
<fastjson.version>1.2.70</fastjson.version>
|
||||
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
||||
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
||||
<mybatis-plus-generator.version>3.5.3.1</mybatis-plus-generator.version>
|
||||
<freemarker.version>2.3.31</freemarker.version>
|
||||
<hutool.version>5.8.25</hutool.version>
|
||||
|
Loading…
Reference in New Issue
Block a user