本身写的代码生成器,保证好用!代码整理中,后面放代码,可先加群下载jar使用:QQ:461964997java
优势:mysql
1,语法简单,即freeMarker语法。git
2,配置,操做简单,maven命令生成sql
3,模板暴露,可扩展自定义模板数据库
使用步骤:mybatis
项目中增长mbg/templates等,以下图所示:app
提示:文件夹的位置能够本身适状况调整位置,只要generatorConfig.xml对应的配置路径对便可。maven
其中url
1,tramp-generator-config_1_0.dtd文件是对generatorConfig.xml配置文件的规范约束。spa
2,*.ftl文件就是咱们想生成的模板文件,使用了freeMarker,因此只要了解freeMarker即可以随意自定义模板。插件内置了属性,可直接使用,具体属性下面说。
3,generatorConfig.xml是插件的核心配置文件,具体描述看下面代码:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//W3C//DTD HTML 4.01//en" "https://ad_earn/dtd/raw/master/tramp-generator-config_1_0.dtd"> <generatorConfiguration> <tables> <!--数据库表,name:数据库中的表名, prefix:表前缀,声明后不会出如今文件名中 module:模块 overwrite:是否覆盖代码,默认false--> <table name="ceb_notice" module="basic" prefix="ceb_" overwrite="true"/> </tables> <!-- 须要执行的组--> <templates path="mbg/templates" targetGroupName="mybatisBase"> <group name="mybatisBase"> <!--模板,name:模板名称(生成的文件名称规则:名称=类名+模板名称,再去除 .ftl后缀) tootPath:根目录(如:resources,java),path:模板生成的文件所要存放的路径,其中${module}的值为table标签module属性对应的值--> <template name="BaseMapper.xml.ftl" rootPath="resources" path="mybatis.base" overwrite="true"/> <template name="#.java.ftl" rootPath="java" path="com.tramp.${module}.entity" overwrite="true"/> <template name="Field.java.ftl" rootPath="java" path="com.tramp.frame.server.base.field" overwrite="true"/> <template name="BaseDao.java.ftl" rootPath="java" path="com.tramp.frame.server.base.dao" overwrite="true"/> <template name="Enum.java.ftl" rootPath="java" path="com.tramp.${module}.enums" overwrite="true"/> <template name="Mapper.xml.ftl" rootPath="resources" path="mybatis"/> <template name="Service.java.ftl" rootPath="java" path="com.tramp.${module}.service"/> <template name="Dao.java.ftl" rootPath="java" path="com.tramp.${module}.dao"/> </group> <group name="tablesToDoc"> <template name="CiTables.doc.ftl" absolutePath="D:\"/> </group> </templates> <types> <type jdbcType="SMALLINT" javaType="Integer"></type> </types> <info author="autoCoder" remark="autoCoder生成"/> <!--目前只支持mysql--> <dataSource dialect="mysql" url="jdbc:mysql://" db="tramp-fan" user="" password="" driverClassName="com.mysql.jdbc.Driver"/> </generatorConfiguration>
<plugin> <groupId>com.tramp</groupId> <artifactId>autoCoder-maven-plugin</artifactId> <version>1.0.6</version> <configuration> <configPath>${basedir}/mbg/generatorConfig.xml</configPath> </configuration> </plugin>
执行maven命令:
你们能够根据本身项目状况配置对应模板,几分钟就能够配置好啦,不懂freeMarker的花几分钟时间看看,基本够用了。下面贴出插件内置的数据,能够直接拿来用。
以user_addr数据库表为例:有link_mobile属性,类型VARCHAR,注释为:联系电话
属性名 | 属性值 | |||||||||||||||||||||
className | UserAddr | |||||||||||||||||||||
variableName | userAddr | |||||||||||||||||||||
tableName | user_addr | |||||||||||||||||||||
requestBasePath | /user/addr(配置文件配置) | |||||||||||||||||||||
methods | 方法集合(配置文件配置) | |||||||||||||||||||||
author | 做者(配置文件配置) | |||||||||||||||||||||
remark | 配置文件配置 | |||||||||||||||||||||
table |
|
下面贴出模板代码片断供参考:
<resultMap id="baseResultMap" type="com.tramp.basic.entity.${className}"> <id column="id" jdbcType="VARCHAR" property="id" /> <#list table.columnList as field> <#if field.name != 'id'> <result column="${field.name}" property="${field.variableName}" jdbcType="${(field.type=='DATETIME')?string('TIMESTAMP',field.type)}"/> </#if> </#list> </resultMap> <sql id="baseColumnList"> <#list table.columnList as field>${field.name}<#if field_has_next>,</#if></#list> </sql> <select id="get" parameterType="java.lang.String" resultMap="baseResultMap"> select <include refid="baseColumnList"/> from ${table.name} where id = ${'#'}{id,jdbcType=VARCHAR} </select> <delete id="delete" parameterType="java.util.Collection"> delete from ${table.name} where 1=1 and id in <foreach close=")" collection="list" index="index" item="item" open="(" separator=","> ${'#'}{item,jdbcType=VARCHAR} </foreach> </delete>
git地址:https://gitee.com/ad_earn/tramp-generator。须要使用的,能够加qq群交流,下载,QQ:461964997