当前位置:首页 > 技术 > 正文内容

MyBatis代码生成器:动态生成XML映射文件

访客 技术 2026年7月3日 1

实现

在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等类...

标签: MyBatis

相关文章

Linux crontab 详解

1) crontab 是什么cron 是 Linux 的定时任务守护进程;crontab 是用来编辑/查看“按时间周期执行命令”的表(cron table)。常见两类:用户 crontab:每个用户一份(crontab -e 编辑)系统级 crontab / cron.d:可指定执行用户(/etc/crontab、/etc/cron.d/*)2) crontab 时间...

富文本里可以允许的 HTML 属性

一、所有标签默认允许的安全属性(极少)class        (可选)id           (通常建议禁用)title️ 注意:id 容易被滥用做锚点注入,很多系统直接禁用class 允许的话最好只允许固定前缀(如 editor-*)二、a 标签允许属性<a href="" t...

Mac 安装 Node.js 指南

方法一:通过官网安装包(最简单,适合初学者)如果你只是想快速安装并开始使用,这是最直接的方法。访问 Node.js 官网。页面会显示两个版本:LTS (Recommended For Most Users):长期支持版,最稳定。建议选这个。Current:最新特性版,包含最新功能但可能不够稳定。下载 .pkg 安装包并运行。按照安装向导点击“下一步”即可完成。方法二:使用 Homebrew 安装(...

Dom\HTML_NO_DEFAULT_NS 的副作用:自动加闭合标签

在使用Dom\HTMLDocument时,Dom\HTML_NO_DEFAULT_NS 将禁止在解析过程中设置元素的命名空间, 此设置是为了与DOMDocument向后兼容而存在的。当使用它时,已知的一个副作用就是:自动加闭合标签例如 </img> 为什么会这样?当你使用:Dom\HTML_NO_DEFAULT_NS文档会变成 无命名空间模式,此时内部更接近 XML...

Laravel 事件和监听器创建

在 Laravel 中,使用 Artisan 命令创建 Events(事件) 和 Listeners(监听器) 是非常高效的。你可以通过以下几种方式来实现:1. 手动创建单个 Event如果你只想创建一个事件类,可以使用 make:event 命令:Bashphp artisan make:event UserRegistered执行后,文件将生成在 app/Even...

自定义域名解析神器 dnsmasq

什么是 dnsmasq?dnsmasq 是一个轻量级、功能强大的网络服务工具,专为小型和中等规模网络设计。它是一个综合的网络基础设施解决方案[1]。dnsmasq 能做什么?功能说明应用场景DNS 转发与缓存将 DNS 查询转发到上游服务器(ISP、Google DNS 等),并在本地缓存结果加快 DNS 查询速度,减少外部 DNS 流量本地 DNS解析本地网络设备的主机名,无需编辑&n...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。