MyBatis Generator automatically creates code
1. First install the mybatis plugin on eclipse
2. Create a mavenWeb project.
3. Write an xml in the resource, it must have the same name as mine
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE generatorConfiguration 3 PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" 4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 5 <generatorConfiguration> 6 <properties resource="db.properties" /> 7 <context id="mysqlTables" targetRuntime="MyBatis3"> 8 <jdbcConnection driverClass="${jdbc.driver}" 9 connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}" /> 11 <!--Specify the generated type as java type to avoid type fields such as number in the database --> 10 <javaTypeResolver> 12 <property name="forceBigDecimals" value="false" /> 13 </javaTypeResolver> 14 <!--Storage package path of automatically generated entities--> 15 <javaModelGenerator targetPackage="com.bw.pojo " 16 targetProject="src/main/java"> 17 <property name="enableSubPackages" value="true" /> 18 <property name="trimStrings" value="true" /> 19 </javaModelGenerator> 20 <! --Automatically generated *Mapper.xml file storage path--> 21 < sqlMapGenerator targetPackage="com.bw.mapper" 22 targetProject="src/main/java"> 23 <property name="enableSubPackages" value="true" /> 24 </sqlMapGenerator> 25 <!--自动生成的*Mapper.java存放路径 --> 26 <javaClientGenerator type="XMLMAPPER" 27 targetPackage="com.bw.mapper" targetProject="src/main/java"> 28 <property name="enableSubPackages" value="true" /> 29 </javaClientGenerator> 30 <table tableName="user" domainObjectName="User" 31 enableCountByExample="false" enableUpdateByExample="false" 32 enableDeleteByExample="false" enableSelectByExample="false" 33 selectByExampleQueryId="false"></table> 34 </context> 35 </generatorConfiguration>
1) At this time table is the table in my database.
2) This line is the database connection properties file I wrote. You must write a corresponding resource location
3) Be sure to create the location of your generated files, such as com.**.pojo; com.**.mapper...etc
4. Note, right click --> run As, --> mavenBuild , fill in mybatis-generator:generate in Goals, and click run directly
5. Results:
Without accumulating small currents, rivers and seas cannot be formed, and without silicon accumulation, one step cannot reach thousands of miles.