Skip to content

Commit e4314b7

Browse files
committed
添加代码生成器获取表和列信息的逻辑
1 parent a54b006 commit e4314b7

File tree

15 files changed

+724
-0
lines changed

15 files changed

+724
-0
lines changed

src/main/java/com/company/project/Application.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.slf4j.LoggerFactory;
66
import org.springframework.boot.SpringApplication;
77
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.annotation.ComponentScan;
9+
import org.springframework.context.annotation.Import;
810

911
/**
1012
*
@@ -17,6 +19,8 @@
1719
* @Description:自定义符号日志输出代码来源 RuoYi:https://github.com/lerry903/RuoYi(在其基础上为其添加颜色输出展示)
1820
**/
1921
@SpringBootApplication
22+
@ComponentScan(basePackages={"cn.hutool.extra.spring"})
23+
@Import(cn.hutool.extra.spring.SpringUtil.class)
2024
public class Application {
2125
private static Logger log = LoggerFactory.getLogger(Application.class);
2226
public static void main(String[] args) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.company.project.generator.mapper;
2+
3+
import com.company.project.generator.model.GenTable;
4+
import com.company.project.generator.model.GenTableColumn;
5+
import org.apache.ibatis.annotations.Mapper;
6+
7+
import java.util.List;
8+
9+
/**
10+
* @author ruoyi
11+
*
12+
* @Editor: zhuoqianmingyue
13+
* @ModifiedDate: 2020/7/14 10:49 下午
14+
* @Description:参考 RuoYi 项目代码生成器代码 代码开源项目地址 RuoYi:https://github.com/lerry903/RuoYi
15+
**/
16+
@Mapper
17+
public interface CodeGenneratorMapper {
18+
19+
/**
20+
* 根据表名查询表的信息
21+
*
22+
* @param tableName 表名称
23+
* @return 表信息
24+
*/
25+
public GenTable selectTableByTableName(String tableName);
26+
27+
/**
28+
* 查询据库表的所有列的信息
29+
*
30+
* @param tableName 表名
31+
* @return 数据库表列的集合
32+
*/
33+
public List<GenTableColumn> selectTableColumnsByTableName(String tableName);
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.company.project.generator.model;
2+
3+
/**
4+
* 处理日期类型字段
5+
*
6+
* @Author: zhuoqianmingyue
7+
* @Date: 2020/7/26 8:29 上午
8+
* @Description:参考RuoYi 项目代码生成器处理逻辑 代码开源项目地址 RuoYi:https://github.com/lerry903/RuoYi
9+
**/
10+
public class DateFieldTypeState extends SetJavaFieldTypeState {
11+
12+
@Override
13+
public void setJavaType(GenTableColumn tableColumn) {
14+
String dataType = getDbType(tableColumn.getColumnType());
15+
16+
if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)){
17+
tableColumn.setJavaType(GenConstants.TYPE_DATE);
18+
}else{
19+
switchState(dataType,tableColumn);
20+
}
21+
}
22+
23+
@Override
24+
public void switchState(String dataType, GenTableColumn tableColumn) {
25+
26+
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType)){
27+
tableColumn.setCurrent(new SetStringFieldTypeState()).getJavaType();
28+
}
29+
30+
if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
31+
tableColumn.setCurrent(new NumbeFieldTypeState()).getJavaType();
32+
}
33+
}
34+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.company.project.generator.model;
2+
3+
/**
4+
* 代码生成通用常量
5+
*
6+
* @author ruoyi
7+
*
8+
* @Editor:zhuoqianmingyue
9+
* @ModifiedDate: 2020/07/26
10+
* @Description:去除部分Monkey使用不到的常量。代码开源项目地址 RuoYi:https://github.com/lerry903/RuoYi
11+
*/
12+
public class GenConstants {
13+
14+
/** 数据库字符串类型 */
15+
public static final String[] COLUMNTYPE_STR = { "char", "varchar", "narchar", "varchar2", "tinytext", "text",
16+
"mediumtext", "longtext" };
17+
18+
/** 数据库时间类型 */
19+
public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" };
20+
21+
/** 数据库数字类型 */
22+
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
23+
"bigint", "float", "double", "decimal" };
24+
25+
/** Entity基类字段 */
26+
public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
27+
28+
29+
/** 文本框 */
30+
public static final String HTML_INPUT = "input";
31+
32+
/** 文本域 */
33+
public static final String HTML_TEXTAREA = "textarea";
34+
35+
/** 下拉框 */
36+
public static final String HTML_SELECT = "select";
37+
38+
/** 单选框 */
39+
public static final String HTML_RADIO = "radio";
40+
41+
/** 复选框 */
42+
public static final String HTML_CHECKBOX = "checkbox";
43+
44+
/** 日期控件 */
45+
public static final String HTML_DATETIME = "datetime";
46+
47+
/** 字符串类型 */
48+
public static final String TYPE_STRING = "String";
49+
50+
/** 整型 */
51+
public static final String TYPE_INTEGER = "Integer";
52+
53+
/** 长整型 */
54+
public static final String TYPE_LONG = "Long";
55+
56+
/** 浮点型 */
57+
public static final String TYPE_DOUBLE = "Double";
58+
59+
/** 高精度计算类型 */
60+
public static final String TYPE_BIGDECIMAL = "BigDecimal";
61+
62+
/** 时间类型 */
63+
public static final String TYPE_DATE = "Date";
64+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package com.company.project.generator.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonFormat;
4+
5+
import javax.validation.constraints.NotBlank;
6+
import java.util.Date;
7+
import java.util.List;
8+
9+
/**
10+
* 业务表 gen_table
11+
* @author ruoyi
12+
*
13+
* @Editor: zhuoqianmingyue
14+
* @ModifiedDate: 2020/7/14 10:49 下午
15+
* @Description:参考 RuoYi 项目代码生成器代码 代码开源项目地址 RuoYi:https://github.com/lerry903/RuoYi
16+
**/
17+
public class GenTable {
18+
private static final long serialVersionUID = 1L;
19+
20+
/** 编号 */
21+
private Long tableId;
22+
23+
/** 表名称 */
24+
private String tableName;
25+
26+
/** 表描述 */
27+
private String tableComment;
28+
29+
/** 实体类名称(首字母大写) */
30+
private String className;
31+
32+
/** 生成包路径 */
33+
@NotBlank(message = "生成包路径不能为空")
34+
private String packageName;
35+
36+
/** 生成模块名 */
37+
@NotBlank(message = "生成模块名不能为空")
38+
private String moduleName;
39+
40+
/** 生成业务名 */
41+
@NotBlank(message = "生成业务名不能为空")
42+
private String businessName;
43+
44+
/** 生成功能名 */
45+
@NotBlank(message = "生成功能名不能为空")
46+
private String functionName;
47+
48+
/** 生成作者 */
49+
@NotBlank(message = "作者不能为空")
50+
private String functionAuthor;
51+
52+
/** 主键信息 */
53+
private GenTableColumn pkColumn;
54+
55+
/** 创建时间 */
56+
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
57+
private Date createTime;
58+
59+
/** 更新者 */
60+
private String updateBy;
61+
62+
/** 更新时间 */
63+
private Date updateTime;
64+
65+
66+
/** 表列信息 */
67+
private List<GenTableColumn> columns;
68+
69+
public Long getTableId() {
70+
return tableId;
71+
}
72+
73+
public void setTableId(Long tableId) {
74+
this.tableId = tableId;
75+
}
76+
77+
public String getTableName() {
78+
return tableName;
79+
}
80+
81+
public void setTableName(String tableName) {
82+
this.tableName = tableName;
83+
}
84+
85+
public String getTableComment() {
86+
return tableComment;
87+
}
88+
89+
public void setTableComment(String tableComment) {
90+
this.tableComment = tableComment;
91+
}
92+
93+
public String getClassName() {
94+
return className;
95+
}
96+
97+
public void setClassName(String className) {
98+
this.className = className;
99+
}
100+
101+
public String getPackageName() {
102+
return packageName;
103+
}
104+
105+
public void setPackageName(String packageName) {
106+
this.packageName = packageName;
107+
}
108+
109+
public String getModuleName() {
110+
return moduleName;
111+
}
112+
113+
public void setModuleName(String moduleName) {
114+
this.moduleName = moduleName;
115+
}
116+
117+
public String getBusinessName() {
118+
return businessName;
119+
}
120+
121+
public void setBusinessName(String businessName) {
122+
this.businessName = businessName;
123+
}
124+
125+
public String getFunctionName() {
126+
return functionName;
127+
}
128+
129+
public void setFunctionName(String functionName) {
130+
this.functionName = functionName;
131+
}
132+
133+
public String getFunctionAuthor() {
134+
return functionAuthor;
135+
}
136+
137+
public void setFunctionAuthor(String functionAuthor) {
138+
this.functionAuthor = functionAuthor;
139+
}
140+
141+
public GenTableColumn getPkColumn() {
142+
return pkColumn;
143+
}
144+
145+
public void setPkColumn(GenTableColumn pkColumn) {
146+
this.pkColumn = pkColumn;
147+
}
148+
149+
public List<GenTableColumn> getColumns() {
150+
return columns;
151+
}
152+
153+
public void setColumns(List<GenTableColumn> columns) {
154+
this.columns = columns;
155+
}
156+
}

0 commit comments

Comments
 (0)