parent
67ac3f9eb7
commit
8debf3f523
Binary file not shown.
Binary file not shown.
@ -1,57 +0,0 @@
|
|||||||
package com.charge;
|
|
||||||
|
|
||||||
import com.alibaba.druid.wall.WallFilter;
|
|
||||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
||||||
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
|
||||||
import com.jfinal.plugin.druid.DruidPlugin;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class ActiveRecordPluginConfig {
|
|
||||||
//通过SpringBoot获取到数据库配置
|
|
||||||
@Value("${spring.datasource.username}")
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.url}")
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.driver-class-name}")
|
|
||||||
private String driverClassName;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ActiveRecordPlugin initActiveRecordPlugin() {
|
|
||||||
DruidPlugin druidPlugin = new DruidPlugin(url, username, password, driverClassName);
|
|
||||||
|
|
||||||
// 加强数据库安全
|
|
||||||
WallFilter wallFilter = new WallFilter();
|
|
||||||
wallFilter.setDbType("mysql");
|
|
||||||
druidPlugin.addFilter(wallFilter);
|
|
||||||
druidPlugin.start();
|
|
||||||
|
|
||||||
// 配置ActiveRecord插件
|
|
||||||
ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
|
|
||||||
arp.setDialect(new MysqlDialect());
|
|
||||||
//遍历sql目录下所有的sql文件
|
|
||||||
File sqlDir;
|
|
||||||
String basePath = ActiveRecordPluginConfig.class.getClassLoader().getResource(".").getPath();
|
|
||||||
basePath = basePath.replace("/target/test-classes/", "/target/classes/");
|
|
||||||
sqlDir = new File(basePath + "/Sql");
|
|
||||||
File[] sqlFiles = sqlDir.listFiles();
|
|
||||||
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
|
||||||
//只加载.sql文件
|
|
||||||
if (sqlFile.getName().indexOf(".sql") > 0) {
|
|
||||||
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//加载
|
|
||||||
arp.start();
|
|
||||||
return arp;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
package com.charge.tools;
|
|
||||||
|
|
||||||
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 com.zaxxer.hikari.HikariConfig;
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class GenerateMysqlDoc {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String fileOutputDir = "c:\\";
|
|
||||||
//数据源
|
|
||||||
HikariConfig hikariConfig = new HikariConfig();
|
|
||||||
hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
|
|
||||||
hikariConfig.setJdbcUrl("jdbc:mysql://10.10.14.210:22066/yltcharge?useUnicode=true&characterEncoding=UTF-8&useSSL=false");
|
|
||||||
hikariConfig.setUsername("root");
|
|
||||||
hikariConfig.setPassword("DsideaL147258369");
|
|
||||||
//设置可以获取tables remarks信息
|
|
||||||
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
|
|
||||||
hikariConfig.setMinimumIdle(2);
|
|
||||||
hikariConfig.setMaximumPoolSize(5);
|
|
||||||
DataSource dataSource = new HikariDataSource(hikariConfig);
|
|
||||||
//生成配置
|
|
||||||
EngineConfig engineConfig = EngineConfig.builder()
|
|
||||||
//生成文件路径
|
|
||||||
.fileOutputDir(fileOutputDir)
|
|
||||||
//打开目录
|
|
||||||
.openOutputDir(true)
|
|
||||||
//文件类型
|
|
||||||
.fileType(EngineFileType.HTML)
|
|
||||||
//生成模板实现
|
|
||||||
.produceType(EngineTemplateType.freemarker)
|
|
||||||
//自定义文件名称
|
|
||||||
.fileName("驿来特数据库文档").build();
|
|
||||||
|
|
||||||
//忽略表
|
|
||||||
ArrayList<String> ignoreTableName = new ArrayList<>();
|
|
||||||
//ignoreTableName.add("test_user");
|
|
||||||
//ignoreTableName.add("test_group");
|
|
||||||
//忽略表前缀
|
|
||||||
ArrayList<String> ignorePrefix = new ArrayList<>();
|
|
||||||
//ignorePrefix.add("test_");
|
|
||||||
//忽略表后缀
|
|
||||||
ArrayList<String> ignoreSuffix = new ArrayList<>();
|
|
||||||
//ignoreSuffix.add("_test");
|
|
||||||
|
|
||||||
ProcessConfig processConfig = ProcessConfig.builder()
|
|
||||||
//指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置
|
|
||||||
//根据名称指定表生成
|
|
||||||
.designatedTableName(new ArrayList<>())
|
|
||||||
//根据表前缀生成
|
|
||||||
.designatedTablePrefix(new ArrayList<>())
|
|
||||||
//根据表后缀生成
|
|
||||||
.designatedTableSuffix(new ArrayList<>())
|
|
||||||
//忽略表名
|
|
||||||
.ignoreTableName(ignoreTableName)
|
|
||||||
//忽略表前缀
|
|
||||||
.ignoreTablePrefix(ignorePrefix)
|
|
||||||
//忽略表后缀
|
|
||||||
.ignoreTableSuffix(ignoreSuffix).build();
|
|
||||||
//配置
|
|
||||||
Configuration config = Configuration.builder()
|
|
||||||
//版本
|
|
||||||
.version("1.0.0")
|
|
||||||
//描述
|
|
||||||
.description("驿来特数据库设计文档生成")
|
|
||||||
//数据源
|
|
||||||
.dataSource(dataSource)
|
|
||||||
//生成配置
|
|
||||||
.engineConfig(engineConfig)
|
|
||||||
//生成配置
|
|
||||||
.produceConfig(processConfig)
|
|
||||||
.build();
|
|
||||||
//执行生成
|
|
||||||
new DocumentationExecute(config).execute();
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue