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> <!--数据库驱动jar包的真实路径 --> <classPathEntry location="D:\JAVA\mysql-connector-java-5.1.34_1.jar"/> <context id="context" targetRuntime="MyBatis3"> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <commentGenerator> <property name="suppressAllComments" value="false"/> <property name="suppressDate" value="true"/> </commentGenerator> <!--数据库连接的信息:驱动类、连接地址、用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/tedu_store" userId="root" password="123"> <!--预防不同数据库中有名字相同的表--> <property name="nullCatalogMeansCurrent" value="true"/> </jdbcConnection> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!--指定包名生成实体类 以及生成的地址 (可以自定义地址,如果路径不存在会自动创建) --> <javaModelGenerator targetPackage="entity" targetProject=".\src\main\java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false"/> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- !!!! Mapper XML Configurations !!!! --> <sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources"> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <!-- !!!! Mapper Interface Configurations !!!! --> <javaClientGenerator targetPackage="mapper" targetProject=".\src\main\java" type="XMLMAPPER"> <property name="enableSubPackages" value="false"/> </javaClientGenerator> <!-- 指定数据库和表 domainObjectName="User" 指定表生成对应的实体类名--> <table schema="tedu_store" tableName="t_user" domainObjectName="User" enableCountByExample="true" enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true" selectByExampleQueryId="true"> <!--插入数据后返回主键--> <generatedKey column="id" sqlStatement="MySql" identity="true"/> </table> <!--<table schema="db_wechat" tableName="t_automessage" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/> <table schema="db_wechat" tableName="t_command" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>--> </context> </generatorConfiguration>到现在为止,所有的mybatis配置工作已经结束了,话不多说,直接实际操作,来生产实体类。
点击菜单中的Run->Edit Configuration,然后在弹出窗体的左上角,点击+然后选择maven,会出现如下图所示 然后apply后,再点run; 最后生成的目录如下图所示: 至此关于IDEA下使用idea-mybatis-generator进行mybatis逆向工程生成entity(实体类所放的包),mapper(接口文件所放的包)的流程就全部结束了,感兴趣的小伙伴赶紧试试吧。有问题欢迎留言。
本文为原创,转载请注明出处和作者,谢谢!