mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
使用 screw 生成接口文档
This commit is contained in:
40
lab-70-db-doc/lab-70-db-doc-screw-03/pom.xml
Normal file
40
lab-70-db-doc/lab-70-db-doc-screw-03/pom.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>lab-70-db-doc</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-70-db-doc-screw-03</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- screw 库,简洁好用的数据库表结构文档生成器 -->
|
||||
<dependency>
|
||||
<groupId>cn.smallbun.screw</groupId>
|
||||
<artifactId>screw-core</artifactId>
|
||||
<version>1.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.smallbun.screw</groupId>
|
||||
<artifactId>screw-extension</artifactId>
|
||||
<version>1.0.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 数据库连接 -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.4.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.22</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,72 @@
|
||||
import cn.smallbun.screw.core.Configuration;
|
||||
import cn.smallbun.screw.core.engine.EngineConfig;
|
||||
import cn.smallbun.screw.core.engine.EngineFileType;
|
||||
import cn.smallbun.screw.core.engine.EngineTemplateType;
|
||||
import cn.smallbun.screw.core.execute.DocumentationExecute;
|
||||
import cn.smallbun.screw.core.process.ProcessConfig;
|
||||
import cn.smallbun.screw.extension.pojo.PojoConfiguration;
|
||||
import cn.smallbun.screw.extension.pojo.execute.PojoExecute;
|
||||
import cn.smallbun.screw.extension.pojo.strategy.HumpNameStrategy;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ScrewMain {
|
||||
|
||||
private static final String DB_URL = "jdbc:mysql://400-infra.server.iocoder.cn:3306";
|
||||
private static final String DB_NAME = "mall_system";
|
||||
private static final String DB_USERNAME = "root";
|
||||
private static final String DB_PASSWORD = "3WLiVUBEwTbvAfsh";
|
||||
|
||||
private static final String FILE_OUTPUT_DIR = "/Users/yunai/screw_test";
|
||||
private static final String JAVA_CLASS_PACKAGE = "cn.iocoder.dataobject";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 创建 screw 的配置
|
||||
PojoConfiguration config = PojoConfiguration.builder()
|
||||
.path(FILE_OUTPUT_DIR) // 生成 POJO 相关的目录
|
||||
.packageName(JAVA_CLASS_PACKAGE) // 包名
|
||||
.nameStrategy(new HumpNameStrategy()) // 包名策略
|
||||
.useLombok(false) // 是否使用 Lombok
|
||||
.dataSource(buildDataSource()) // 数据源
|
||||
.processConfig(buildProcessConfig()) // 处理配置
|
||||
.build();
|
||||
|
||||
// 执行 screw,生成 POJO 实体类
|
||||
new PojoExecute(config).execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据源
|
||||
*/
|
||||
private static DataSource buildDataSource() {
|
||||
// 创建 HikariConfig 配置类
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
hikariConfig.setJdbcUrl(DB_URL + "/" + DB_NAME);
|
||||
hikariConfig.setUsername(DB_USERNAME);
|
||||
hikariConfig.setPassword(DB_PASSWORD);
|
||||
hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息
|
||||
// 创建数据源
|
||||
return new HikariDataSource(hikariConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 screw 的处理配置,一般可忽略
|
||||
* 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置
|
||||
*/
|
||||
private static ProcessConfig buildProcessConfig() {
|
||||
return ProcessConfig.builder()
|
||||
.designatedTableName(Collections.<String>emptyList()) // 根据名称指定表生成
|
||||
.designatedTablePrefix(Collections.<String>emptyList()) //根据表前缀生成
|
||||
.designatedTableSuffix(Collections.<String>emptyList()) // 根据表后缀生成
|
||||
.ignoreTableName(Arrays.asList("test_user", "test_group")) // 忽略表名
|
||||
.ignoreTablePrefix(Collections.singletonList("test_")) // 忽略表前缀
|
||||
.ignoreTableSuffix(Collections.singletonList("_test")) // 忽略表后缀
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
<modules>
|
||||
<module>lab-70-db-doc-screw-01</module>
|
||||
<module>lab-70-db-doc-screw-02</module>
|
||||
<module>lab-70-db-doc-screw-03</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user