master
周文涛 2 years ago
parent 537759af7e
commit 9965bf2e56

@ -69,4 +69,22 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>

@ -59,33 +59,38 @@ public class Main {
private static String dbType = "postgresql"; private static String dbType = "postgresql";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
//1.数据库配置
String driver = "org.postgresql.Driver"; String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://10.201.145.19:35432/enjoy-oqc?stringtype=unspecified&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false"; String url = "jdbc:postgresql://10.201.145.19:35432/enjoy-oqc?stringtype=unspecified&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false";
String user = "enjoy"; String user = "enjoy";
String password = "Nomi1234"; String password = "Nomi1234";
List<TableEntityVo> tableEntityVoList = printTableStructure(driver, url, user, password, "oqc_project"); //2.选择表配置
String table= "oqc_spot_check_record";
generate(bussi_package, "oqc_spot_check_record", "OqcSpotCheckRecord","抽检记录表", tableEntityVoList); String entityName="OqcSpotCheckRecord";//实体类
String description = "抽检记录表";//备注
String primaryKeyField = "id";//主键
List<TableEntityVo> tableEntityVoList = printTableStructure(driver, url, user, password, table);
//3.生成
generate(bussi_package, table,primaryKeyField,entityName,description, tableEntityVoList);
} }
/** /**
*
* @param bussiPackage * @param bussiPackage
* @param tableName * @param tableName
* @param entityName * @param entityName
* @param originalColumns * @param originalColumns
*/ */
private static void generate(String bussiPackage, String tableName, String entityName,String description, List<TableEntityVo> originalColumns) { private static void generate(String bussiPackage,String tableName,String primaryKeyField,String entityName,String description, List<TableEntityVo> originalColumns) {
TableVo tableVo = new TableVo(); TableVo tableVo = new TableVo();
tableVo.setFtlDescription(description); tableVo.setFtlDescription(description);
//包名 //包名
Map<String, Object> dataMap = new HashMap<>(); Map<String, Object> dataMap = new HashMap<>();
dataMap.put("bussiPackage", bussiPackage);//包 dataMap.put("bussiPackage", bussiPackage);//包
dataMap.put("entityPackage", "domain"); dataMap.put("entityPackage", "domain");//实体类包名 domain/entity
dataMap.put("tableName", tableName);//表名称 dataMap.put("tableName", tableName);//表名称
dataMap.put("tableVo", tableVo);//表属性 dataMap.put("tableVo", tableVo);//表属性
//主键 //主键
dataMap.put("primaryKeyField", "id"); dataMap.put("primaryKeyField",primaryKeyField);
dataMap.put("entityName", entityName);//实体类名称 dataMap.put("entityName", entityName);//实体类名称
dataMap.put("author", author);//作者 dataMap.put("author", author);//作者

@ -22,7 +22,7 @@ public class MarkerGenerate {
public static void generate(String basePackagePath,String templateName,String parsePath,String fileName,Map<String,Object> dataMap) { public static void generate(String basePackagePath,String templateName,String parsePath,String fileName,Map<String,Object> dataMap) {
String entityName = (String) dataMap.get("entityName"); String entityName = (String) dataMap.get("entityName");
if (StringUtils.isNotBlank(entityName)) { if (StringUtils.isNotBlank(entityName)) {
dataMap.put("uncap_first",StringUtils.uncapitalize(entityName)); dataMap.put("uncap_first",StringUtils.uncapitalize(entityName));//实体类首字母缩写参数
} }
// 创建生成文件所在目录 // 创建生成文件所在目录
@ -62,30 +62,14 @@ public class MarkerGenerate {
if (StringUtils.isNotBlank(folder)) { if (StringUtils.isNotBlank(folder)) {
File file =new File(folder); File file =new File(folder);
if (file.exists()) { if (file.exists()) {
if (file.isDirectory()) { if (file.isDirectory()) {/*System.out.println("dir exists");*/}
System.out.println("dir exists");
}
else { else {
System.out.println("the same name file exists, can not create dir"); System.out.println("the same name file exists, can not create dir");
} }
} else { } else {
System.out.println("dir not exists, create it ..."); //System.out.println("目录不存在,创建");
file.mkdirs(); file.mkdirs();
} }
/*String[] folderSpilt = folder.split(File.separator);
StringBuffer sb=new StringBuffer();
for (String f : folderSpilt) {
sb=sb.append(f);
File file=new File(sb.toString());
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}*/
} }
} }
} }

Loading…
Cancel
Save