整合 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:
|
server:
|
||||||
port: 8000
|
port: 8000
|
||||||
spring:
|
spring:
|
||||||
|
application:
|
||||||
|
name: gateway
|
||||||
cloud:
|
cloud:
|
||||||
gateway:
|
gateway:
|
||||||
routes:
|
routes:
|
||||||
|
@ -23,6 +23,10 @@
|
|||||||
<artifactId>common</artifactId>
|
<artifactId>common</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.yovinchen.train.member;
|
package com.yovinchen.train.member;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
@ -16,6 +17,7 @@ import org.springframework.core.env.Environment;
|
|||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ComponentScan("com.yovinchen")
|
@ComponentScan("com.yovinchen")
|
||||||
|
@MapperScan("com.yovinchen.train.member.mapper")
|
||||||
public class MemberApplication {
|
public class MemberApplication {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MemberApplication.class);
|
private static final Logger LOG = LoggerFactory.getLogger(MemberApplication.class);
|
||||||
|
|
||||||
|
@ -1,18 +1,32 @@
|
|||||||
package com.yovinchen.train.member.controller;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 会员 前端控制器
|
* 会员 前端控制器
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:10:59
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/member")
|
@RequestMapping("/member")
|
||||||
public class MemberController {
|
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>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:10:59
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/passenger")
|
@RequestMapping("/passenger")
|
||||||
public class PassengerController {
|
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>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:36:29
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -17,7 +17,7 @@ import java.util.Date;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:36:29
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:10:59
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface MemberMapper extends BaseMapper<Member> {
|
public interface MemberMapper extends BaseMapper<Member> {
|
||||||
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:10:59
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface PassengerMapper extends BaseMapper<Passenger> {
|
public interface PassengerMapper extends BaseMapper<Passenger> {
|
||||||
|
@ -9,7 +9,7 @@ import com.yovinchen.train.member.entity.Member;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:10:59
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
public interface MemberService extends IService<Member> {
|
public interface MemberService extends IService<Member> {
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import com.yovinchen.train.member.entity.Passenger;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:10:59
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
public interface PassengerService extends IService<Passenger> {
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.yovinchen.train.member.entity.Member;
|
import com.yovinchen.train.member.entity.Member;
|
||||||
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:10:59
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.yovinchen.train.member.entity.Passenger;
|
import com.yovinchen.train.member.entity.Passenger;
|
||||||
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yovinchen
|
* @author yovinchen
|
||||||
* @since 2024-01-19 04:10:59
|
* @since 2024-01-19 09:53:20
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class PassengerServiceImpl extends ServiceImpl<PassengerMapper, Passenger> implements PassengerService {
|
public class PassengerServiceImpl extends ServiceImpl<PassengerMapper, Passenger> implements PassengerService {
|
@ -7,9 +7,23 @@ spring:
|
|||||||
name: member
|
name: member
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
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
|
url: jdbc:mysql://82.157.68.223:3306/train?characterEncoding=utf-8&useSSL=false
|
||||||
name: train
|
|
||||||
password: train
|
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-openapi项目配置
|
||||||
springdoc:
|
springdoc:
|
||||||
swagger-ui:
|
swagger-ui:
|
||||||
|
2
pom.xml
2
pom.xml
@ -23,7 +23,7 @@
|
|||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<spring-cloud.version>2022.0.0</spring-cloud.version>
|
<spring-cloud.version>2022.0.0</spring-cloud.version>
|
||||||
<fastjson.version>1.2.70</fastjson.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>
|
<mybatis-plus-generator.version>3.5.3.1</mybatis-plus-generator.version>
|
||||||
<freemarker.version>2.3.31</freemarker.version>
|
<freemarker.version>2.3.31</freemarker.version>
|
||||||
<hutool.version>5.8.25</hutool.version>
|
<hutool.version>5.8.25</hutool.version>
|
||||||
|
Loading…
Reference in New Issue
Block a user