Mybatis generator自动生成代码包括实体,dao,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> <!-- 数据库驱动包位置 --> <classPathEntry location="E:\work\jar\mysql-connector-java-5.1.39-bin.jar" /> <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" /> --> <context id="DB2Tables" targetRuntime="MyBatis3"> <!--去除注释 --> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 数据库链接URL、用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://10.80.5.52:3306/lte1" userId="root" password="aaaaaa"> <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa"> --> </jdbcConnection> <!--默认false Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC. --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成实体类的包名和位置,这里配置将生成的实体类放在com.bss.entity这个包下 --> <javaModelGenerator targetPackage="entity" targetProject="E:\Users\GDMMYD\JLLT\src\com\bss\"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的SQL映射文件包名和位置,这里配置将生成的SQL映射文件放在com.bss.mapping这个包下 --> <sqlMapGenerator targetPackage="mapping" targetProject="E:\Users\GDMMYD\JLLT\src\com\bss\"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置,这里配置将生成的dao类放在com.bss.mapper这个包下 --> <javaClientGenerator type="XMLMAPPER" targetPackage="mapper" targetProject="E:\Users\GDMMYD\JLLT\src\com\bss\"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 要生成那些表(更改tableName和domainObjectName就可以) --> <table tableName="t_sys_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> </context> </generatorConfiguration>
在所在文件的命令行内输入参数:
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml
-overwrite
然后就是显示:
MyBatis Generator finished successfully.那就说明生成成功了!!!