MyBatis代码生成器:动态生成XML映射文件
实现
在XML文件中填充的内容主要是针对数据库表的增删改查操作,代码如下:
package com.generator.builder;
import com.generator.bean.Config;
import com.generator.bean.TableMeta;
import com.generator.bean.ColumnMeta;
import com.generator.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.ArrayUtils;
import java.io.*;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
public class XmlMapperGenerator {
private static final Logger logger = LoggerFactory.getLogger(XmlMapperGenerator.class);
private static final String BASE_COLUMN_LIST = "base_column_list";
private static final String BASE_QUERY_CONDITION = "base_query_condition";
private static final String BASE_QUERY_CONDITION_EXTEND = "base_query_condition_extend";
private static final String BASE_CONDITION = "base_condition";
private static final String QUERY_CONDITION = "query_condition";
public static void generateXml(TableMeta tableMeta) {
File folder = new File(Config.XML_OUTPUT_PATH);
if (!folder.exists()) {
folder.mkdirs();
}
String xmlName = tableMeta.getBeanName() + Config.MAPPER_SUFFIX;
File file = new File(folder, xmlName + ".xml");
OutputStream out = null;
OutputStreamWriter outw = null;
BufferedWriter bw = null;
try {
out = new FileOutputStream(file);
outw = new OutputStreamWriter(out, Charset.defaultCharset());
bw = new BufferedWriter(outw);
//fixed head
bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
bw.newLine();
bw.write("");
bw.newLine();
bw.newLine();
//mapper
bw.write("<mapper namespace=\"" + Config.MAPPER_PACKAGE + "." + xmlName + "\">");
bw.newLine();
bw.newLine();
//Entity mapping
bw.write("\t<!--Entity mapping-->");
bw.newLine();
String poReference = Config.PO_PACKAGE + "." + tableMeta.getBeanName();
bw.write("\t<resultMap id=\"base_result_map\" type=\"" + poReference + "\">");
bw.newLine();
ColumnMeta primary = null;
int size = 0;
Map<String, List<ColumnMeta>> keyIndexMap = tableMeta.getKeyIndexMap();
for (Map.Entry<String, List<ColumnMeta>> entry : keyIndexMap.entrySet()) {
if (entry.getKey().equals("PRIMARY")) {
if (entry.getValue().size() > 1) size = 2;
else {
primary = entry.getValue().get(0);
size = 1;
}
}
}
StringBuilder fieldString = new StringBuilder();//prepare for generic query result column
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
fieldString.append(columnMeta.getFieldName()).append(",");
if (size == 1 && columnMeta.getFieldName().equals(primary.getFieldName())) {
bw.write("\t\t<id" + " column=\"" + columnMeta.getFieldName() + "\" property=\"" + columnMeta.getPropertyName() + "\"" + "></id>");
} else {
bw.write("\t\t<result" + " column=\"" + columnMeta.getFieldName() + "\" property=\"" + columnMeta.getPropertyName() + "\"" + "></result>");
}
bw.newLine();
}
bw.write("\t</resultMap>");
bw.newLine();
bw.newLine();
//generic query result column
bw.write("\t<!--generic query result column-->");
bw.newLine();
bw.write("\t<sql id=\"" + BASE_COLUMN_LIST + "\">");
bw.newLine();
bw.write("\t\t" + fieldString.substring(0, fieldString.length() - 1));
bw.newLine();
bw.write("\t</sql>");
bw.newLine();
bw.newLine();
//base query condition
bw.write("\t<!--base query condition-->");
bw.newLine();
bw.write("\t<sql id=\"" + BASE_QUERY_CONDITION + "\">");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
if (ArrayUtils.contains(Config.SQL_STRING_TYPES, columnMeta.getSqlType())) {
bw.write("\t\t<if test=\"query." + columnMeta.getPropertyName() + " !=null and query." + columnMeta.getPropertyName() + "!=''\">");
} else {
bw.write("\t\t<if test=\"query." + columnMeta.getPropertyName() + " !=null\">");
}
bw.newLine();
bw.write("\t\t\tand " + columnMeta.getFieldName() + " = #{query." + columnMeta.getPropertyName() + "}");
bw.newLine();
bw.write("\t\t</if>");
bw.newLine();
}
bw.write("\t</sql>");
bw.newLine();
bw.newLine();
//extended query condition
bw.write("\t<!--extended query condition-->");
bw.newLine();
bw.write("\t<sql id=\"" + BASE_QUERY_CONDITION_EXTEND + "\">");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnExtendList()) {
bw.write("\t\t<if test=\"query." + columnMeta.getPropertyName() + " !=null and query." + columnMeta.getPropertyName() + "!=''\">");
bw.newLine();
if (ArrayUtils.contains(Config.SQL_STRING_TYPES, columnMeta.getSqlType())) {
bw.write("\t\t\tand " + columnMeta.getFieldName() + " like concat('%', #{query." + columnMeta.getPropertyName() + "}, '%')");
bw.newLine();
} else if (ArrayUtils.contains(Config.SQL_DATE_TYPES, columnMeta.getSqlType()) || ArrayUtils.contains(Config.SQL_DATE_TIME_TYPES, columnMeta.getSqlType())) {
if (columnMeta.getPropertyName().endsWith(Config.TIME_START_SUFFIX)) {
bw.write("\t\t\t<![CDATA[ and " + columnMeta.getFieldName() + ">=str_to_date(#{query." + columnMeta.getPropertyName() + "}, '%Y-%m-%d') ]]>");
bw.newLine();
} else {
bw.write("\t\t\t<![CDATA[ and " + columnMeta.getFieldName() + "< date_sub(str_to_date(#{query." + columnMeta.getPropertyName() + "}, '%Y-%m-%d'),interval -1 day) ]]>");
bw.newLine();
}
}
bw.write("\t\t</if>");
bw.newLine();
}
bw.write("\t</sql>");
bw.newLine();
bw.newLine();
//Common query condition column
bw.write("\t<!--Common query condition column-->");
bw.newLine();
bw.write("\t<sql id=\"" + QUERY_CONDITION + "\">");
bw.newLine();
bw.write("\t\t<where>");
bw.newLine();
bw.write("\t\t\t <include refid=\"" + BASE_QUERY_CONDITION + "\"/>");
bw.newLine();
bw.write("\t\t\t<include refid=\"" + BASE_QUERY_CONDITION_EXTEND + "\"/>");
bw.newLine();
bw.write("\t\t</where>");
bw.newLine();
bw.write("\t</sql>");
bw.newLine();
bw.newLine();
//query collection
bw.write("\t<!--query collection-->");
bw.newLine();
bw.write("\t<select id=\"selectList\" resultMap=\"base_result_map\">");
bw.newLine();
bw.write("\t\tSELECT");
bw.newLine();
bw.write("\t\t<include refid=\"" + BASE_COLUMN_LIST + "\"/>");
bw.newLine();
bw.write("\t\tFROM " + tableMeta.getTableName());
bw.newLine();
bw.write("\t\t<include refid=\"" + QUERY_CONDITION + "\"/>");
bw.newLine();
bw.write("\t\t<if test=\"query.orderBy!=null\">");
bw.newLine();
bw.write("\t\t\torder by ${query.orderBy}");
bw.newLine();
bw.write("\t\t</if>");
bw.newLine();
bw.write("\t\t<if test=\"query.simplePage!=null\">");
bw.newLine();
bw.write("\t\t\tlimit #{query.simplePage.start},#{query.simplePage.end}");
bw.newLine();
bw.write("\t\t</if>");
bw.newLine();
bw.write("\t</select>");
bw.newLine();
bw.newLine();
//query count
bw.write("\t<!--query count-->");
bw.newLine();
bw.write("\t<select id=\"selectCount\" resultType=\"java.lang.Long\">");
bw.newLine();
bw.write("\t\tSELECT");
bw.newLine();
bw.write("\t\tcount(1)");
bw.newLine();
bw.write("\t\tFROM " + tableMeta.getTableName());
bw.newLine();
bw.write("\t\t<include refid=\"" + QUERY_CONDITION + "\"/>");
bw.newLine();
bw.write("\t</select>");
bw.newLine();
bw.newLine();
//insert(seacher for notnull value)
bw.write("\t<!--insert(seacher for notnull value)-->");
bw.newLine();
bw.write("\t<insert id=\"insert\" parameterType=\"" + Config.PO_PACKAGE + "." + tableMeta.getBeanName() + "\">");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
if (columnMeta.getIsAutoIncrement() != null && columnMeta.getIsAutoIncrement()) {
bw.write("\t\t<selectKey keyProperty=\"bean." + columnMeta.getPropertyName() + "\" resultType=\"Integer\" order=\"AFTER\">");
bw.newLine();
bw.write("\t\t\tSELECT LAST_INSERT_ID()");
bw.newLine();
bw.write("\t\t</selectKey>");
bw.newLine();
break;
}
}
bw.write("\t\tINSERT INTO " + tableMeta.getTableName());
bw.newLine();
bw.write("\t\t<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
bw.write("\t\t\t<if test=\"bean." + columnMeta.getPropertyName() + " != null\">");
bw.newLine();
bw.write("\t\t\t\t" + columnMeta.getFieldName() + ",");
bw.newLine();
bw.write("\t\t\t</if>");
bw.newLine();
}
bw.write("\t\t</trim>");
bw.newLine();
bw.write("\t\t<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\">");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
bw.write("\t\t\t<if test=\"bean." + columnMeta.getPropertyName() + " != null\">");
bw.newLine();
bw.write("\t\t\t\t#{bean." + columnMeta.getPropertyName() + "},");
bw.newLine();
bw.write("\t\t\t</if>");
bw.newLine();
}
bw.write("\t\t</trim>");
bw.newLine();
bw.write("\t</insert>");
bw.newLine();
bw.newLine();
//insert or update
bw.write("\t<!--insert or update-->");
bw.newLine();
bw.write("\t<insert id=\"insertOrUpdate\" parameterType=\"" + Config.PO_PACKAGE + "." + tableMeta.getBeanName() + "\">");
bw.newLine();
bw.write("\t\tINSERT INTO " + tableMeta.getTableName());
bw.newLine();
bw.write("\t\t<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
bw.write("\t\t\t<if test=\"bean." + columnMeta.getPropertyName() + " != null\">");
bw.newLine();
bw.write("\t\t\t\t" + columnMeta.getFieldName() + ",");
bw.newLine();
bw.write("\t\t\t</if>");
bw.newLine();
}
bw.write("\t\t</trim>");
bw.newLine();
bw.write("\t\t<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\">");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
bw.write("\t\t\t<if test=\"bean." + columnMeta.getPropertyName() + " != null\">");
bw.newLine();
bw.write("\t\t\t\t#{bean." + columnMeta.getPropertyName() + "},");
bw.newLine();
bw.write("\t\t\t</if>");
bw.newLine();
}
bw.write("\t\t</trim>");
bw.newLine();
bw.write("\t\ton DUPLICATE key update");
bw.newLine();
bw.write("\t\t<trim prefix=\"\" suffix=\"\" suffixOverrides=\",\">");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
if(!columnMeta.getPropertyName().equals(primary.getPropertyName())){
bw.write("\t\t\t<if test=\"bean." + columnMeta.getPropertyName() + " != null\">");
bw.newLine();
bw.write("\t\t\t\t" + columnMeta.getFieldName() + " = VALUES(" + columnMeta.getFieldName() + "),");
bw.newLine();
bw.write("\t\t\t</if>");
bw.newLine();
}
}
bw.write("\t\t</trim>");
bw.newLine();
bw.write("\t</insert>");
bw.newLine();
bw.newLine();
//insert Batch
bw.write("\t<!--insert Batch-->");
bw.newLine();
bw.write("\t<insert id=\"insertBatch\" parameterType=\"" + Config.PO_PACKAGE + "." + tableMeta.getBeanName() +"\">");
bw.newLine();
StringBuilder insertBatchFieldString = new StringBuilder();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
if(columnMeta.getIsAutoIncrement()!=null&&columnMeta.getIsAutoIncrement())continue;
insertBatchFieldString.append(columnMeta.getFieldName()+",");
}
bw.write("\t\tINSERT INTO "+tableMeta.getTableName()+"("+insertBatchFieldString.substring(0, insertBatchFieldString.length() - 1)+")");
bw.newLine();
bw.write("\t\t<foreach collection=\"list\" item=\"item\" separator=\",\">");
bw.newLine();
bw.write("\t\t\t(");
bw.newLine();
StringBuilder insertBatchString = new StringBuilder();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
if(columnMeta.getIsAutoIncrement()!=null&&columnMeta.getIsAutoIncrement())continue;
insertBatchString.append("#(item."+columnMeta.getPropertyName()+"),");
}
bw.write("\t\t\t"+insertBatchString.substring(0,insertBatchString.length()-1));
bw.newLine();
bw.write("\t\t\t)");
bw.newLine();
bw.write("\t\t</foreach>");
bw.newLine();
bw.write("\t</insert>");
bw.newLine();
bw.newLine();
//insert or update Batch
bw.write("\t<!--insert or update Batch-->");
bw.newLine();
bw.write("\t<insert id=\"insertOrDpdateBatch\" parameterType=\"" + Config.PO_PACKAGE + "." + tableMeta.getBeanName() +"\">");
bw.newLine();
bw.write("\t\tINSERT INTO "+tableMeta.getTableName()+"("+insertBatchFieldString.substring(0, insertBatchFieldString.length() - 1)+")");
bw.newLine();
bw.write("\t\t<foreach collection=\"list\" item=\"item\" separator=\",\">");
bw.newLine();
bw.write("\t\t\t(");
bw.newLine();
bw.write("\t\t\t"+insertBatchString.substring(0,insertBatchString.length()-1));
bw.newLine();
bw.write("\t\t\t)");
bw.newLine();
bw.write("\t\t</foreach>");
bw.newLine();
bw.write("\t\ton DUPLICATE key update");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
if(columnMeta.getIsAutoIncrement()!=null&&columnMeta.getIsAutoIncrement())continue;
bw.write("\t\t"+columnMeta.getFieldName()+" = VALUES("+columnMeta.getFieldName()+"),");
bw.newLine();
}
bw.write("\t</insert>");
bw.newLine();
bw.newLine();
// //update by id
// bw.write("\t<!--update by id-->");
// bw.newLine();
// bw.write("\t<update id=\"updateById\" parameterType=\"" + Config.PO_PACKAGE + "." + tableMeta.getBeanName() +"\">");
// bw.newLine();
// bw.write("\t\tUPDATE "+tableMeta.getTableName());
// bw.newLine();
// bw.write("\t\t<set>");
// bw.newLine();
// for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
// if(columnMeta.getIsAutoIncrement()!=null&&columnMeta.getIsAutoIncrement())continue;
// bw.write("\t\t\t<if test=\"bean."+columnMeta.getPropertyName()+" != null\">");
// bw.newLine();
// bw.write("\t\t\t\t"+columnMeta.getFieldName()+" = #{bean."+columnMeta.getPropertyName()+"},");
// bw.newLine();
// bw.write("\t\t\t</if>");
// bw.newLine();
// }
// bw.write("\t\t</set>");
// bw.newLine();
// bw.write("\t\twhere id=#{id}");
// bw.newLine();
// bw.write("\t</update>");
// bw.newLine();
// bw.newLine();
//create baseMethods for index(index) or unique(index) fields
//create methods
for(Map.Entry<String,List<ColumnMeta>> entry :keyIndexMap.entrySet()) {
List<ColumnMeta> columnMetaList = entry.getValue();
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (ColumnMeta columnMeta : columnMetaList) {
sb.append(StringUtil.upperCaseFirstLetter(columnMeta.getPropertyName()));
sb2.append(columnMeta.getFieldName()+"=#{"+columnMeta.getPropertyName()+"} and ");
sb.append("And");
}
String substring = sb.substring(0, sb.length() - 3);
String substring2 = sb2.substring(0, sb2.length() - 5);
//select method
bw.write("\t<!--select by "+substring+"-->");
bw.newLine();
bw.write("\t<select id=\"selectBy"+substring+"\" resultMap=\"base_result_map\">");
bw.newLine();
bw.write("\t\tselect");
bw.newLine();
bw.write("\t\t<include refid=\""+BASE_COLUMN_LIST+"\"/>");
bw.newLine();
bw.write("\t\tfrom "+tableMeta.getTableName()+" where "+substring2);
bw.newLine();
bw.write("\t</select>");
bw.newLine();
bw.newLine();
//update method
bw.write("\t<!--update by "+substring+"-->");
bw.newLine();
bw.write("\t<update id=\"updateBy"+substring+"\" parameterType=\""+Config.PO_PACKAGE+"."+tableMeta.getBeanName()+"\">");
bw.newLine();
bw.write("\t\tUPDATE "+tableMeta.getTableName());
bw.newLine();
bw.write("\t\t<set>");
bw.newLine();
for (ColumnMeta columnMeta : tableMeta.getColumnList()) {
if(columnMeta.getIsAutoIncrement()!=null&&columnMeta.getIsAutoIncrement())continue;
bw.write("\t\t\t<if test=\"bean."+columnMeta.getPropertyName()+" != null\">");
bw.newLine();
bw.write("\t\t\t\t"+columnMeta.getFieldName()+" = #{bean."+columnMeta.getPropertyName()+"},");
bw.newLine();
bw.write("\t\t\t</if>");
bw.newLine();
}
bw.write("\t\t</set>");
bw.newLine();
bw.write("\t\twhere "+substring2);
bw.newLine();
bw.write("\t</update>");
bw.newLine();
bw.newLine();
//
//delete method
bw.write("\t<!--delete by "+substring+"-->");
bw.newLine();
bw.write("\t<delete id=\"deleteBy"+substring+"\">");
bw.newLine();
bw.write("\t\tdelete from "+tableMeta.getTableName()+" where "+substring2);
bw.newLine();
bw.write("\t</delete>");
bw.newLine();
bw.newLine();
}
bw.write("</mapper>");
bw.flush();
} catch (Exception e) {
logger.info("生成xml失败:{}", e);
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (outw != null) {
try {
outw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
所涉及到的配置文件代码
#数据库连接信息
database.username=root
database.password=
database.url=jdbc:mysql://:3000/myspace?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
database.driver-class-name=com.mysql.cj.jdbc.Driver
#是否删除一些数据库表面命名习惯,例如db.user的前缀
exclude.table.prefix=true
#query中BeanParamName后缀
query.bean.param.suffix=Query
#query查询中模糊查询变量命名后缀
query.bean.param.fuzzy.suffix=Fuzzy
#query查询中时间起止查询变量命名后缀
query.bean.param.time.start.suffix=Start
query.bean.param.time.end.suffix=End
#mapper后缀
mapper.suffix=Mapper
#文件输出路径
output.path=E:/BaiduNetdiskDownload/easyjava/easyJava-demo/src/main/
#包名
base.package=com.generator
po.package=entity.po
utils.package=utils
enums.package=enums
query.package=entity.query
mapper.package=mappers
#需要忽略的属性
ignore.bean.tojson.field=password
ignore.bean.tojson.expression=@JsonIgnore
ignore.bean.tojson.class=import com.fasterxml.jackson.annotation.JsonIgnore;
#日期格式序列化
bean.date.format.expression=@JsonFormat(pattern = "%s",timezone = "GMT+8")
bean.date.format.class=import com.fasterxml.jackson.annotation.JsonFormat;
#日期格式反序列化
bean.date.unformat.expression=@DateTimeFormat(pattern = "%s")
bean.date.unformat.class=import org.springframework.format.annotation.DateTimeFormat;
所涉及到的常量类代码
package com.generator.bean;
import com.generator.utils.PropertiesUtil;
/**
* 常量类
*
* @author generator
* @dateTime 2024/11/20 15:45
*/
public class Config {
//another
public static Boolean EXCLUDE_TABLE_PREFIX;
public static String QUERY_BEAN_PARAM_SUFFIX;
//path
private static String PATH_JAVA = "java";
private static String PATH_RESOURCES = "resources";
public static String OUTPUT_PATH;
public static String PO_PATH;
public static String UTILS_PATH;
public static String ENUMS_PATH;
public static String QUERY_PATH;
public static String MAPPER_PATH;
public static String XML_OUTPUT_PATH;
//package
public static String BASE_PACKAGE;
public static String PO_PACKAGE;
public static String UTILS_PACKAGE;
public static String ENUMS_PACKAGE;
public static String QUERY_PACKAGE;
public static String MAPPER_PACKAGE;
//需要忽略的属性
public static String IGNORE_BEAN_TOJSON_FIELD;
public static String IGNORE_BEAN_TOJSON_EXPRESSION;
public static String IGNORE_BEAN_TOJSON_CLASS;
//时间序列化
public static String BEAN_DATE_FORMAT_EXPRESSION;
public static String BEAN_DATE_FORMAT_CLASS;
//时间反序列化
public static String BEAN_DATE_UNFORMAT_EXPRESSION;
public static String BEAN_DATE_UNFORMAT_CLASS;
//query查询中模糊查询变量命名后缀
public static String QUERY_BEAN_PARAM_FUZZY_SUFFIX;
//query查询中时间起止查询变量命名后缀
public static String QUERY_BEAN_PARAM_TIME_START_SUFFIX;
public static String QUERY_BEAN_PARAM_TIME_END_SUFFIX;
//mapper后缀
public static String MAPPER_SUFFIX;
static {
//another
EXCLUDE_TABLE_PREFIX = Boolean.valueOf(PropertiesUtil.getString("exclude.table.prefix"));
QUERY_BEAN_PARAM_SUFFIX = PropertiesUtil.getString("query.bean.param.suffix");
//package
BASE_PACKAGE = PropertiesUtil.getString("base.package");
PO_PACKAGE = BASE_PACKAGE + "." + PropertiesUtil.getString("po.package");
UTILS_PACKAGE = BASE_PACKAGE + "." + PropertiesUtil.getString("utils.package");
ENUMS_PACKAGE = BASE_PACKAGE + "." + PropertiesUtil.getString("enums.package");
QUERY_PACKAGE = BASE_PACKAGE + "." + PropertiesUtil.getString("query.package");
MAPPER_PACKAGE = BASE_PACKAGE + "." + PropertiesUtil.getString("mapper.package");
//path
OUTPUT_PATH = PropertiesUtil.getString("output.path") + PATH_JAVA + "/";
PO_PATH = OUTPUT_PATH + PO_PACKAGE.replace(".", "/");
UTILS_PATH = OUTPUT_PATH + UTILS_PACKAGE.replace(".", "/");
ENUMS_PATH = OUTPUT_PATH + ENUMS_PACKAGE.replace(".", "/");
QUERY_PATH = OUTPUT_PATH + QUERY_PACKAGE.replace(".", "/");
MAPPER_PATH = OUTPUT_PATH + MAPPER_PACKAGE.replace(".", "/");
XML_OUTPUT_PATH = PropertiesUtil.getString("output.path") + PATH_RESOURCES + "/" + MAPPER_PACKAGE.replace(".", "/");
//Attributes to be ignored
IGNORE_BEAN_TOJSON_FIELD = PropertiesUtil.getString("ignore.bean.tojson.field");
IGNORE_BEAN_TOJSON_EXPRESSION = PropertiesUtil.getString("ignore.bean.tojson.expression");
IGNORE_BEAN_TOJSON_CLASS = PropertiesUtil.getString("ignore.bean.tojson.class");
//time serialization
BEAN_DATE_FORMAT_EXPRESSION = PropertiesUtil.getString("bean.date.format.expression");
BEAN_DATE_FORMAT_CLASS = PropertiesUtil.getString("bean.date.format.class");
//time deserialization
BEAN_DATE_UNFORMAT_EXPRESSION = PropertiesUtil.getString("bean.date.unformat.expression");
BEAN_DATE_UNFORMAT_CLASS = PropertiesUtil.getString("bean.date.unformat.class");
//Fuzzy query variable name suffix in query
QUERY_BEAN_PARAM_FUZZY_SUFFIX = PropertiesUtil.getString("query.bean.param.fuzzy.suffix");
//Query query time start and end query variable name suffix
QUERY_BEAN_PARAM_TIME_START_SUFFIX = PropertiesUtil.getString("query.bean.param.time.start.suffix");
QUERY_BEAN_PARAM_TIME_END_SUFFIX = PropertiesUtil.getString("query.bean.param.time.end.suffix");
//Mapper suffix
MAPPER_SUFFIX = PropertiesUtil.getString("mapper.suffix");
}
public final static String[] SQL_DATE_TIME_TYPES = new String[]{"datetime", "timestamp"};
public final static String[] SQL_DATE_TYPES = new String[]{"date"};
public final static String[] SQL_DECIMAL_TYPES = new String[]{"decimal", "double", "float"};
public final static String[] SQL_STRING_TYPES = new String[]{"char", "varchar", "text,mediumtext", "longtext"};
public final static String[] SQL_INTEGER_TYPES = new String[]{"int", "tinyint"};
public final static String[] SQL_LONG_TYPES = new String[]{"bigint"};
public static void main(String[] args) {
System.out.println(XML_OUTPUT_PATH);
}
}
后言
接下来将生成controller和service等类...