MyBatis数据库测试代码自动生成

<!-- generatorConfig.xml配置,其中:<plugin type="org.mybatis.generator.plugins.ToStringPlugin" /> 可以直接将list返回值展示出来,而非地址-->
<?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>
<!-- 设置mysql驱动路径, 当使用cmd命令自动生成时,需要打开classPathEntry配置; 使用java类生成时,需要注释classPathEntry配置 -->
<!-- <classPathEntry location="./mysql-connector-java-5.1.27.jar" /> -->
<!-- 此处指定生成针对MyBatis3的DAO -->
<context id="context1" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" />
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
<property name="searchString" value="Example$" />
<property name="replaceString" value="Criteria" />
</plugin>
<!-- 去掉生成出来的代码的注解 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>

<!-- jdbc连接信息 -->
<!-- jdbc:oracle:thin:@172.30.29.147:1521:orcl oracle.jdbc.OracleDriver -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.138.254:3306/jdd_user?characterEncoding=utf8" userId="root"
password="jdd.com" />

<!-- 默认false,表示把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer; true表示把JDBC DECIMAL
和 NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<!-- 生成bean对象 -->
<javaModelGenerator targetPackage="cn.springmvc.model"
targetProject="../ssm/src/main/java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<!--<property name="enableSubPackages" value="true" /> -->
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>

<!-- 生成sqlMap xml -->
<sqlMapGenerator targetPackage="mapper"
targetProject="../ssm/src/main/resources" />

<!-- 生成DAO的类文件 -->
<javaClientGenerator targetPackage="cn.springmvc.dao"
targetProject="../ssm/src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>

<table tableName="user_base_info" domainObjectName="UserBaseInfo"></table>

<!-- 想要生成的数据库表,自动化工具会根据该表的结构生成相应的bean对象 -->
<!-- <table tableName="content" domainObjectName="Content"></table>
<table tableName="content_pic" domainObjectName="ContentPic"></table>-->

<!-- <table tableName="content_pic" domainObjectName="ContentPic"></table> -->
<!-- <table tableName="sinoicity_user" domainObjectName="User"></table>
<table tableName="sinoicity_dept" domainObjectName="Dept"></table> <table
tableName="sinoicity_function" domainObjectName="Function"></table> <table
tableName="sinoicity_role" domainObjectName="Role"></table> <table tableName="sinoicity_upmessage"
domainObjectName="Upmessage"></table> <table tableName="sinoicity_funcrole"
domainObjectName="Funcrole"></table> -->
</context>
</generatorConfiguration>

<!-- 1.打开当前配置项classPathEntry 2.打开cmd,到含有mybatis-generator-core-1.3.2.jar的目录中,cd
D:ideawebmailmanagersrcmainwebappWEB-INFlib 3.java -jar mybatis-generator-core-1.3.2.jar
-configfile D:ideawebmailmanagersrc est esourcesgeneratorConfig.xml
-overwrite -->
原文地址:https://www.cnblogs.com/cristin/p/7756263.html