Skip to content

Commit 86723d7

Browse files
author
YunaiV
committed
使用 screw 生成接口文档
1 parent ab27b89 commit 86723d7

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>lab-70-db-doc</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-70-db-doc-screw-03</artifactId>
13+
14+
<dependencies>
15+
<!-- screw 库,简洁好用的数据库表结构文档生成器 -->
16+
<dependency>
17+
<groupId>cn.smallbun.screw</groupId>
18+
<artifactId>screw-core</artifactId>
19+
<version>1.0.5</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>cn.smallbun.screw</groupId>
23+
<artifactId>screw-extension</artifactId>
24+
<version>1.0.5</version>
25+
</dependency>
26+
27+
<!-- 数据库连接 -->
28+
<dependency>
29+
<groupId>com.zaxxer</groupId>
30+
<artifactId>HikariCP</artifactId>
31+
<version>3.4.5</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>mysql</groupId>
35+
<artifactId>mysql-connector-java</artifactId>
36+
<version>8.0.22</version>
37+
</dependency>
38+
</dependencies>
39+
40+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import cn.smallbun.screw.core.Configuration;
2+
import cn.smallbun.screw.core.engine.EngineConfig;
3+
import cn.smallbun.screw.core.engine.EngineFileType;
4+
import cn.smallbun.screw.core.engine.EngineTemplateType;
5+
import cn.smallbun.screw.core.execute.DocumentationExecute;
6+
import cn.smallbun.screw.core.process.ProcessConfig;
7+
import cn.smallbun.screw.extension.pojo.PojoConfiguration;
8+
import cn.smallbun.screw.extension.pojo.execute.PojoExecute;
9+
import cn.smallbun.screw.extension.pojo.strategy.HumpNameStrategy;
10+
import com.zaxxer.hikari.HikariConfig;
11+
import com.zaxxer.hikari.HikariDataSource;
12+
13+
import javax.sql.DataSource;
14+
import java.util.Arrays;
15+
import java.util.Collections;
16+
17+
public class ScrewMain {
18+
19+
private static final String DB_URL = "jdbc:mysql://400-infra.server.iocoder.cn:3306";
20+
private static final String DB_NAME = "mall_system";
21+
private static final String DB_USERNAME = "root";
22+
private static final String DB_PASSWORD = "3WLiVUBEwTbvAfsh";
23+
24+
private static final String FILE_OUTPUT_DIR = "/Users/yunai/screw_test";
25+
private static final String JAVA_CLASS_PACKAGE = "cn.iocoder.dataobject";
26+
27+
public static void main(String[] args) {
28+
// 创建 screw 的配置
29+
PojoConfiguration config = PojoConfiguration.builder()
30+
.path(FILE_OUTPUT_DIR) // 生成 POJO 相关的目录
31+
.packageName(JAVA_CLASS_PACKAGE) // 包名
32+
.nameStrategy(new HumpNameStrategy()) // 包名策略
33+
.useLombok(false) // 是否使用 Lombok
34+
.dataSource(buildDataSource()) // 数据源
35+
.processConfig(buildProcessConfig()) // 处理配置
36+
.build();
37+
38+
// 执行 screw,生成 POJO 实体类
39+
new PojoExecute(config).execute();
40+
}
41+
42+
/**
43+
* 创建数据源
44+
*/
45+
private static DataSource buildDataSource() {
46+
// 创建 HikariConfig 配置类
47+
HikariConfig hikariConfig = new HikariConfig();
48+
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
49+
hikariConfig.setJdbcUrl(DB_URL + "/" + DB_NAME);
50+
hikariConfig.setUsername(DB_USERNAME);
51+
hikariConfig.setPassword(DB_PASSWORD);
52+
hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息
53+
// 创建数据源
54+
return new HikariDataSource(hikariConfig);
55+
}
56+
57+
/**
58+
* 创建 screw 的处理配置,一般可忽略
59+
* 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置
60+
*/
61+
private static ProcessConfig buildProcessConfig() {
62+
return ProcessConfig.builder()
63+
.designatedTableName(Collections.<String>emptyList()) // 根据名称指定表生成
64+
.designatedTablePrefix(Collections.<String>emptyList()) //根据表前缀生成
65+
.designatedTableSuffix(Collections.<String>emptyList()) // 根据表后缀生成
66+
.ignoreTableName(Arrays.asList("test_user", "test_group")) // 忽略表名
67+
.ignoreTablePrefix(Collections.singletonList("test_")) // 忽略表前缀
68+
.ignoreTableSuffix(Collections.singletonList("_test")) // 忽略表后缀
69+
.build();
70+
}
71+
72+
}

lab-70-db-doc/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<modules>
1616
<module>lab-70-db-doc-screw-01</module>
1717
<module>lab-70-db-doc-screw-02</module>
18+
<module>lab-70-db-doc-screw-03</module>
1819
</modules>
1920

2021
</project>

0 commit comments

Comments
 (0)