代码自动生成
用的是装载插件的方式生成
安装成功后,需要重启eclipse
使用自动生成代码需要
数据库有货 、插件要装、生成的目录要设置
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>
<context id="MySqlContext" targetRuntime="MyBatis3" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<property name="javaFileEncoding" value="UTF-8"/>
<!-- 为模型生成序列化方法-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<!-- 为生成的Java模型创建一个toString方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<!-- 生成 mapper.xml时不 merge 直接覆盖原文件 -->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"/>
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/hospital2?useUnicode=true&characterEncoding=utf8"
userId="root"
password="1234qwer">
<!--防止生成其他库同名表-->
<property name="nullCatalogMeansCurrent" value="true" />
</jdbcConnection>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="true" />
</javaTypeResolver>
<!-- 生成 Entity 类存放位置,需要指明所在的包名,所在的项目地址:地址为本地的绝对路径,到项目的java目录 -->
<javaModelGenerator targetPackage="com.management.hospital.entity" targetProject="hospital/src/main/java"/>
<!-- 生成映射xml文件存放位置 -->
<sqlMapGenerator targetPackage="mapper.xml" targetProject="hospital/src/main/resources"/>
<!-- 生成 Dao 类存放位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.management.hospital.mapper" targetProject="hospital/src/main/java"/>
<!-- 指定要生成的表名 -->
<!-- <table tableName="ware" domainObjectName="Ware"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table tableName="outbound" domainObjectName="Outbound"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table> -->
<table tableName="material" domainObjectName="Material"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
生成代码结构如下: