Last active
July 18, 2017 14:14
-
-
Save jahentao/2ec550b437cad6971baa7116bec3bed3 to your computer and use it in GitHub Desktop.
mybatis 逆向代码生成配置
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
也可在线使用国内[最著名]的mybatis代码生成网站 --- fwjava.com | |
----------------------------------------------------------------- | |
第一步:先安装mybatis-generator插件; | |
第二步:创建maven项目, 在src/main/resources下创建generatorConfig.xml | |
第三步:配置generatorConfig.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> | |
<!-- 引入配置文件 --> | |
<properties resource="jdbc.properties"/> | |
<!-- 制定数据连接驱动jar地址 --> | |
<classPathEntry location="${path}"/> | |
<!-- 一个数据库对应一个context --> | |
<context id="db_context"> | |
<!-- 注释 --> | |
<commentGenerator> | |
<property name="suppressAllComments" value="true"/><!-- 是否取消注释 --> | |
<property name="suppressDate" value="false" /> <!-- 是否生成注释代时间戳--> | |
</commentGenerator> | |
<!-- jdbc连接 --> | |
<jdbcConnection driverClass="${driverClassName}" | |
connectionURL="${url1}" | |
userId="${username}" password="${password}" /> | |
<javaTypeResolver> | |
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) --> | |
<property name="forceBigDecimals" value="false"/> | |
</javaTypeResolver> | |
<!-- 生成实体类地址 --> | |
<javaModelGenerator targetPackage="com.ssm.domain" targetProject="${projectName}" > | |
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> | |
<property name="enableSubPackages" value="false"/> | |
<!-- 是否针对string类型的字段在set的时候进行trim调用 --> | |
<property name="trimStrings" value="true"/> | |
</javaModelGenerator> | |
<!-- 生成mapxml文件 --> | |
<sqlMapGenerator targetPackage="com.ssm.dao" targetProject="${projectName}"> | |
<property name="enableSubPackages" value="false"/> | |
</sqlMapGenerator> | |
<!-- 生成mapxml对应client,也就是接口dao --> | |
<javaClientGenerator targetPackage="com.ssm.dao" | |
targetProject="${projectName}" type="XMLMAPPER" > | |
<property name="enableSubPackages" value="false" /> | |
</javaClientGenerator> | |
<!-- 配置表信息 --> | |
<!-- | |
schema即为数据库名 tableName为对应的数据库表 | |
domainObjectName是要生成的实体类 enable*ByExample是否生成 example类 | |
--> | |
<table schema="${database}" tableName="sys_user" | |
domainObjectName="User" enableCountByExample="false" | |
enableDeleteByExample="false" enableSelectByExample="false" | |
enableUpdateByExample="false"> | |
<!-- 忽略列,不生成bean 字段 --> | |
<ignoreColumn column="FRED" /> | |
<columnOverride column="id" property="id" javaType="java.lang.Long"/> | |
</table> | |
<table schema="${database}" tableName="sys_attachment" | |
domainObjectName="Attachment" enableCountByExample="false" | |
enableDeleteByExample="false" enableSelectByExample="false" | |
enableUpdateByExample="false"> | |
<!-- 忽略列,不生成bean 字段 --> | |
<ignoreColumn column="FRED" /> | |
<columnOverride column="id" property="id" javaType="java.lang.Long"/> | |
<columnOverride column="createTime" property="create_time" javaType="java.util.Date"/> | |
<columnOverride column="creater" property="creater" javaType="java.lang.Long"/> | |
</table> | |
</context> | |
</generatorConfiguration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
driverClassName=com.mysql.jdbc.Driver | |
url=jdbc\:mysql\://localhost\:3306/test?useUnicode\=true&characterEncoding\=UTF-8 | |
username=root | |
password=*** | |
maxIdle=5 | |
maxActive=40 | |
defaultAutoCommit=false | |
timeBetweenEvictionRunsMillis=3600000 | |
minEvictableIdleTimeMillis=3600000 | |
url1=jdbc:mysql://localhost:3306/test | |
path=E:/mysql-connector-java-5.1.18.jar | |
projectName=ssm | |
database=test | |
# 配置好之后,就可以测试了。 | |
# 第四步:测试,右键generatorConfig.xml 点击Generate Mybatis/Ibatis Artifacts,然后刷新项目去检测有没有生成代码吧。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment