Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bootdo/src/main/java/com/bootdo/common/domain/ColumnDO.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class ColumnDO {
private String attrType;
// auto_increment
private String extra;
// jdbcType
private String jdbcType;

public String getColumnName() {
return columnName;
Expand Down Expand Up @@ -90,4 +92,22 @@ public String toString() {
", extra='" + extra + '\'' +
'}';
}

/**
* 获取 jdbcType
*
* @return jdbcType jdbcType
*/
public String getJdbcType() {
return this.jdbcType;
}

/**
* 设置 jdbcType
*
* @param jdbcType jdbcType
*/
public void setJdbcType(String jdbcType) {
this.jdbcType = jdbcType;
}
}
27 changes: 26 additions & 1 deletion bootdo/src/main/java/com/bootdo/common/utils/GenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,33 @@
*/
public class GenUtils {

/**
* MySQL数据类型到mybatis jdbcType的映射关系
*/
private static Map<String, String> mysqlTypeToJdbcTypeMap = new HashMap<>();
static {
mysqlTypeToJdbcTypeMap.put("blob", "BLOB");
mysqlTypeToJdbcTypeMap.put("char", "CHAR");
mysqlTypeToJdbcTypeMap.put("varchar", "VARCHAR");
mysqlTypeToJdbcTypeMap.put("datetime", "TIMESTAMP");
mysqlTypeToJdbcTypeMap.put("timestamp", "TIMESTAMP");
mysqlTypeToJdbcTypeMap.put("time", "TIME");
mysqlTypeToJdbcTypeMap.put("numeric", "NUMERIC");
mysqlTypeToJdbcTypeMap.put("decimal", "DECIMAL");
mysqlTypeToJdbcTypeMap.put("double", "DOUBLE");
mysqlTypeToJdbcTypeMap.put("float", "FLOAT");
mysqlTypeToJdbcTypeMap.put("tinyint", "TINYINT");
mysqlTypeToJdbcTypeMap.put("int", "INTEGER");
mysqlTypeToJdbcTypeMap.put("smallint", "SMALLINT");
mysqlTypeToJdbcTypeMap.put("mediumint", "INTEGER");
mysqlTypeToJdbcTypeMap.put("bigint", "BIGINT");
mysqlTypeToJdbcTypeMap.put("text", "CLOB");
mysqlTypeToJdbcTypeMap.put("real", "REAL");
}


public static List<String> getTemplates() {
List<String> templates = new ArrayList<String>();
List<String> templates = new ArrayList<>();
templates.add("templates/common/generator/domain.java.vm");
templates.add("templates/common/generator/Dao.java.vm");
//templates.add("templates/common/generator/Mapper.java.vm");
Expand Down Expand Up @@ -81,6 +105,7 @@ public static void generatorCode(Map<String, String> table,
//列的数据类型,转换成Java类型
String attrType = config.getString(columnDO.getDataType(), "unknowType");
columnDO.setAttrType(attrType);
columnDO.setJdbcType(mysqlTypeToJdbcTypeMap.getOrDefault(columnDO.getDataType().toLowerCase(), "OTHER"));

//是否主键
if ("PRI".equalsIgnoreCase(column.get("columnKey")) && tableDO.getPk() == null) {
Expand Down
Loading