对 java 代码进行格式化,使其看上去更加美观

This commit is contained in:
gaohanghang 2020-08-21 23:23:09 +08:00
parent 60bee3cf58
commit ed0bc8e8f8
14 changed files with 766 additions and 718 deletions

View File

@ -6,7 +6,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GeneratorWebApplication {
public static void main(String[] args) {
SpringApplication.run(GeneratorWebApplication.class, args);
}
}

View File

@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

View File

@ -46,4 +46,5 @@ public class WebMvcConfig implements WebMvcConfigurer {
converters.add(stringConverter);
converters.add(fastConverter);
}
}

View File

@ -18,6 +18,7 @@ import java.util.Map;
/**
* spring boot code generator
*
* @author zhengk/moshow
*/
@Controller
@ -44,13 +45,21 @@ public class IndexController {
ClassInfo classInfo = null;
switch (paramInfo.getDataType()) {
//JSON模式parse field from json string
case "json":classInfo = TableParseUtil.processJsonToClassInfo(paramInfo);break;
case "json":
classInfo = TableParseUtil.processJsonToClassInfo(paramInfo);
break;
//INSERT SQL模式parse field from insert sql
case "insert-sql":classInfo = TableParseUtil.processInsertSqlToClassInfo(paramInfo);break;
case "insert-sql":
classInfo = TableParseUtil.processInsertSqlToClassInfo(paramInfo);
break;
//正则表达式模式非完善版本parse sql by regex
case "sql-regex":classInfo = TableParseUtil.processTableToClassInfoByRegex(paramInfo);break;
case "sql-regex":
classInfo = TableParseUtil.processTableToClassInfoByRegex(paramInfo);
break;
//默认模式default parse sql by java
default : classInfo = TableParseUtil.processTableIntoClassInfo(paramInfo);break;
default:
classInfo = TableParseUtil.processTableIntoClassInfo(paramInfo);
break;
}
//2.Set the params 设置表格参数

View File

@ -4,10 +4,12 @@ import lombok.Data;
/**
* Post data - ParamInfo
*
* @author zhengkai.blog.csdn.net
*/
@Data
public class ParamInfo {
private String tableSql;
private String authorName;
private String packageName;
@ -23,4 +25,5 @@ public class ParamInfo {
public static String UNDER_SCORE_CASE = "UnderScoreCase";
public static String UPPER_UNDER_SCORE_CASE = "UpperUnderScoreCase";
}
}

View File

@ -6,10 +6,12 @@ import java.io.Serializable;
/**
* common returnT:公共返回封装类
*
* @author zhengkai.blog.csdn.net
*/
@Data
public class ReturnT implements Serializable {
public static final long serialVersionUID = 42L;
public static final int SUCCESS_CODE = 200;
@ -27,39 +29,50 @@ public class ReturnT implements Serializable {
this.code = code;
this.msg = msg;
}
public ReturnT(int code, String msg, Object data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public ReturnT(Object data) {
this.code = SUCCESS_CODE;
this.data = data;
}
public ReturnT(Object data, int count) {
this.code = PAGE_CODE;
this.data = data;
this.count = count;
}
public static ReturnT PAGE(Object data, int count) {
return new ReturnT(data, count);
}
public static ReturnT PAGE(Object data, long count) {
return new ReturnT(data, Integer.parseInt(count + ""));
}
public static ReturnT SUCCESS() {
return new ReturnT(SUCCESS_CODE, OPERATION_SUCCESS);
}
public static ReturnT SUCCESS(String msg) {
return new ReturnT(SUCCESS_CODE, msg);
}
public static ReturnT SUCCESS(Object data) {
return new ReturnT(data);
}
public static ReturnT ERROR(String msg) {
return new ReturnT(FAIL_CODE, msg);
}
public static ReturnT ERROR() {
return new ReturnT(FAIL_CODE, OBJECT_NOT_FOUND);
}
}

View File

@ -8,6 +8,7 @@ import java.util.Map;
/**
* GeneratorService
*
* @author zhengkai.blog.csdn.net
*/
public interface GeneratorService {

View File

@ -19,6 +19,7 @@ import java.util.stream.Collectors;
/**
* GeneratorService
*
* @author zhengkai.blog.csdn.net
*/
@Slf4j
@ -29,8 +30,10 @@ public class GeneratorServiceImpl implements GeneratorService {
private FreemarkerUtil freemarkerTool;
String templateCpnfig = null;
/**
* 从项目中的JSON文件读取String
*
* @author zhengkai.blog.csdn.net
*/
public String getTemplateConfig() throws IOException {
@ -45,8 +48,10 @@ public class GeneratorServiceImpl implements GeneratorService {
//log.info(JSON.toJSONString(templateCpnfig));
return templateCpnfig;
}
/**
* 根据配置的Template模板进行遍历解析得到生成好的String
*
* @author zhengkai.blog.csdn.net
*/
@Override
@ -59,4 +64,5 @@ public class GeneratorServiceImpl implements GeneratorService {
}
return result;
}
}

View File

@ -4,7 +4,9 @@ package com.softdev.system.generator.util;
* @author xuxueli 2018-05-02 21:10:28
*/
public class CodeGenerateException extends RuntimeException {
private static final long serialVersionUID = 42L;
public CodeGenerateException() {
super();
}
@ -26,4 +28,5 @@ public class CodeGenerateException extends RuntimeException {
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -23,14 +23,13 @@ import java.util.Map;
@Component
public class FreemarkerUtil {
@Autowired
private Configuration configuration;
/**
* 传入需要转义的字符串进行转义
* 20200503 zhengkai.blog.csdn.net
* */
*/
public static String escapeString(String originStr) {
return originStr.replaceAll("", "\\#").replaceAll("", "\\$");
}
@ -39,6 +38,7 @@ public class FreemarkerUtil {
* freemarker config
*/
private static Configuration freemarkerConfig = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
static {
try {
//2020-06-21 zhengkai 修复path问题导致jar无法运行而本地项目可以运行的bug
@ -89,5 +89,4 @@ public class FreemarkerUtil {
return htmlText;
}
}

View File

@ -58,4 +58,5 @@ public class StringUtils {
public static void main(String[] args) {
}
}

View File

@ -20,12 +20,14 @@ import java.util.regex.Pattern;
/**
* 表格解析Util
*
* @author zhengkai.blog.csdn.net
*/
public class TableParseUtil {
/**
* 解析DDL SQL生成类信息
*
* @param paramInfo
* @return
*/
@ -157,7 +159,9 @@ public class TableParseUtil {
&& !(columnLine.contains("primary ") && i > 3));
if (specialFlag) {
//如果是oracle的number(x,x)可能出现最后分割残留的,x)这里做排除处理
if(columnLine.length()<5) {continue;}
if (columnLine.length() < 5) {
continue;
}
//2018-9-16 zhengkai 支持'符号以及空格的oracle语句// userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
String columnName = "";
columnLine = columnLine.replaceAll("`", " ").replaceAll("\"", " ").replaceAll("'", "").replaceAll(" ", " ").trim();
@ -189,8 +193,7 @@ public class TableParseUtil {
if (columnLine.contains(" tinyint")) {
//20191115 MOSHOW.K.ZHENG 支持对tinyint的特殊处理
fieldClass = tinyintTransType;
}
else if (columnLine.contains(" int") || columnLine.contains(" smallint")) {
} else if (columnLine.contains(" int") || columnLine.contains(" smallint")) {
fieldClass = Integer.class.getSimpleName();
} else if (columnLine.contains(" bigint")) {
fieldClass = Long.class.getSimpleName();
@ -298,8 +301,10 @@ public class TableParseUtil {
return codeJavaInfo;
}
/**
* 解析JSON生成类信息
*
* @param paramInfo
* @return
*/
@ -327,11 +332,13 @@ public class TableParseUtil {
return codeJavaInfo;
}
/**
* parse SQL by regex
* @author https://github.com/ydq
*
* @param paramInfo
* @return
* @author https://github.com/ydq
*/
public static ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo) {
// field List
@ -377,6 +384,7 @@ public class TableParseUtil {
}
return codeJavaInfo;
}
public static List<FieldInfo> processJsonObjectToFieldList(JSONObject jsonObject) {
// field List
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
@ -469,4 +477,5 @@ public class TableParseUtil {
codeJavaInfo.setFieldList(fieldList);
return codeJavaInfo;
}
}