mybatis代码生成器的xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 配置文件路径在 主要是为了获取application.propertyjdbc的连接值, 因为我这里是application.yml
不知道怎么获取,所以可以不要注释掉-->
<!-- <properties resource="application.properties" />-->
<!-- defaultModelType="flat": flat,该模型只为每张表生成一个实体类,这个实体类包含表中所有的字段,这种模型最简单,推荐使用-->
<context id="mysqlgenerator" targetRuntime="MyBatis3" defaultModelType="flat" >
<!-- 由于beginningDelimiter和endingDelimiter的默认值为双引号("),
在Mysql中不能这么写,所以还要将这两个默认值改为**反单引号(`)**,配置如下:-->
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!-- 生成的Java文件的编码-->
<property name="javaFileEncoding" value="UTF-8"/>
<!-- 格式化java代码-->
<property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
<!-- 格式化XML代码-->
<property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/>
<!-- 设置启用数据库字段下划线映射到java对象的驼峰式命名属性,默认为false-->
<property name="useActualColumnNames" value="true"/>
<!-- mybatis的一些插件 写在这里了解,因为idea中有一个lombok插件@Data有其中某些插件的效果
默认提供了get,set,hashcode,tostring方法-->
<!-- <!– 这个插件用来给Java模型生成equals和hashcode方法–>-->
<!-- <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" />-->
<!-- <!– 这个插件主要用来为生成的Java模型类添加序列化接口,并生成serialVersionUID字段;–>-->
<!-- <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />-->
<!-- <!– 这个插件用来在XXXExample类中生成大小写敏感的LIKE方法–>-->
<!-- <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />-->
<!-- <!– 生成toString方法的插件–>-->
<!-- <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>-->
<!-- suppressAllComments:**阻止**生成注释,默认为false-->
<!-- suppressDate:**阻止**生成的注释包含时间戳,默认为false-->
<!-- 有时候生成注释太多,看的眼花缭乱,所以可以设置不要注释-->
<commentGenerator>
<property name="suppressDate" value="true" />
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- application.yml用这个jdbc的配置-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/zb-shiro?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&useSSL=false"
userId="root"
password="root">
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!-- application.properties可以用这个jdbc配置-->
<!-- <jdbcConnection driverClass="${spring.datasource.driver-class-name}" connectionURL="${spring.datasource.url}"-->
<!-- userId="${spring.datasource.username}" password="${spring.datasource.password}">-->
<!-- </jdbcConnection>-->
<!-- true:使用BigDecimal对应DECIMAL和 NUMERIC数据类型 false:默认, scale>0;length>18:使用BigDecimal; scale=0;length[10,18]:使用Long;scale=0;length[5,9]:使用Integer; scale=0;length<5:使用Short; -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 实体类生成的位置 -->
<javaModelGenerator targetPackage="com.common.code.entity" targetProject="src/main/java">
<!-- 只对MyBatis3有效,如果true就会使用构造方法入参,如果false就会使用setter方式。默认为false-->
<property name="constructorBased" value="false"/>
<!-- 如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性。默认为false-->
<property name="enableSubPackages" value="false" />
<!-- 该属性用来配置实体类属性是否可变,如果设置为true,那么constructorBased不管设置成什么,都会使用构造方法入参,并且不会生成setter方法。如果为false,实体类属性就可以改变。默认为false-->
<property name="immutable" value="false"/>
<!-- 配置基础基类,可以注释掉-->
<!-- <property name="rootClass" value="com.common.code.entity.BaseEntity"/>-->
<!-- 是否对数据库查询结果进行trim操作-->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- *Mapper.xml 文件的位置 -->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- Mapper 接口文件的位置 -->
<javaClientGenerator targetPackage="com.common.code.mapper" targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!-- table这里用的通配符匹配全部的表,另外所有表都有自动增长的id字段。如果不是所有表的配置都一样,可以做针对性的配置。-->
<!-- <table tableName="%">-->
<!-- <generatedKey column="id" sqlStatement="Mysql"/>-->
<!-- </table>-->
<!-- 相关表的配置 alias="user"配置别名
一般代码生成器会生成两个实体类,其中一个是EntiityExample 一般用不到,可以设置为不生成-->
<table tableName="user" domainObjectName="User" alias="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
<!-- 是否使用mysql表中列的名称-->
<!-- <property name="useActualColumnNames" value="true"/>-->
</table>
</context>
</generatorConfiguration>