That generation reverse engineering class, mapper, the interface through which database tables, do not need to write those, very convenient. With symfony automatically generated inside is the same; people say the video is not much use, but I think it is very convenient
Specific steps, first introduced into MyBatis-generator-core.jar,
After copying files look generator.xml: there are notes, it is easy to understand
<? xml Version = " 1.0 " encoding = " UTF-8 " ?> <! DOCTYPE generatorConfiguration the PUBLIC " - // mybatis.org//DTD the Configuration MyBatis Generator 1.0 // EN " " http://mybatis.org/dtd /mybatis-generator-config_1_0.dtd " > <generatorConfiguration> <! - database driver -> <! - If the IDE (eclipse or idea) project was introduced into the jar package, you do not need the absolute configuration of the jar package the path <classpathentry LOCATION = " E: /project/mybatis/lib/mysql-connector-java-5.0.8-bin.jar " /> -> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="false"/> </commentGenerator> <!--数据库链接地址账号密码--> <jdbcConnection userId="root" driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mybatis_generator?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT" password="wen52010"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!--生成Model类存放位置--> <javaModelGenerator targetPackage="Entity" targetProject="src"> <!-- <property name="enableSubPackages" value="true"/>--> <!-- <property name="trimStrings" value="true"/>--> </javaModelGenerator> <!--生成映射文件存放位置--> <sqlMapGenerator targetPackage="Mapper" targetProject="src"> <!-- <property name="enableSubPackages" value="true"/>--> </sqlMapGenerator> <!- generating class storage location Dao -> " <javaClientGenerator type =XMLMAPPER" targetPackage="Mapper" targetProject="src"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <table tableName="Student"></table> <table tableName="Adress"></table> <!--生成对应表及类名--> <!-- <table tableName="category_" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">--> <!-- <property name="my.isgen.usekeys" value="true"/>--> <!-- <generatedKey column="id" sqlStatement="JDBC"/>--> <!-- </table>--> <!-- <table tableName="product_" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> --> </context> </generatorConfiguration>
The path names, and other changes indicate correct,
Among the main function, copy the following code to run on Ok,
File file = new File("src/generator.xml"); List<String> warnings = new ArrayList<String>(); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(file); DefaultShellCallback callback = new DefaultShellCallback(true); MyBatisGenerator generator = new MyBatisGenerator(config,callback,warnings); generator.generate(null);