1.mybatis reverse engineering (I'm using maven repository creation)
Working principle : reverse engineering (via database tables and field information to generate a corresponding method CRUD)
In fact, that is an automatic generation tool
Entity type (POJO) and mapping files (Mapper) dao layer interface methods also automatically generate a series of
Generated basically simple logic code do not have to knock
Such as CRUD do not have to write it directly over the
The first step: plug mybatis reverse engineering package shelf
pom.xml
<dependencies> <!--分页插件--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-ehcache</artifactId> <version>1.0.0</version> </dependency> <!--控制台的--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.26</version> </dependency> <!--控制台的--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.6</version> </dependency> <!--连接数据库的--> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>12.1.0.1-atlassian-hosted</version> </dependency> <!--mybatis的--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.5</version> </dependency> <!--控制台的--> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> <!--执行逆向工程的按钮--> <build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2 </Version > < Configuration > <-! path to the configuration file -> < configurationFile > $ {/src/main/resources/generatorConfig.xml the basedir} </ configurationFile > < Overwrite > to true </ Overwrite > </ Configuration > < ! - plug-in dependencies need to use -> < the dependencies > < dependency > < groupId > com.oracle </ groupId > < artifactId >ojdbc6 </artifactId> <version>11.2.0.3</version> </dependency> </dependencies> </plugin> </plugins> </build>
Step Two: Configure generatorConfig.xml generate address
<? 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 > < context ID =" Test " targetRuntime =" MyBatis 3 " > < commentGenerator > <-! this element is used to specify annotation removal date is included in the generated generated it to true: It is false: NO -> < Property name = "suppressDate" value = "to true" /> <! - whether to remove the automatically generated annotations true: is: to false: NO-> < Property name = "suppressAllComments" value = "to true" /> </ commentGenerator > <-! Database link URL, user name, password -> < JdbcConnection driverClass = "oracle.jdbc.driver.OracleDriver" connectionURL = "jdbc: oracle: thin: @localhost: 1521: database instance name" userId = "database username" password = "database password" > </ JdbcConnection > < javaTypeResolver > <-! forced to use java.math.BigDecimal 类 --> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="com.seecen.entity" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!- <->the package name and location of the generated map file sqlMapGenerator targetPackage="resources.mapper" targetProject="src/main/resource"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.seecen.dao" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 要生成哪些表 表名 数据库名 实体类名 --> <table tableName="t_user_info" schema="sc" domainObjectName="UserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"/> <table tableName="Emp" domainObjectName="Emp" schema="sc" ->the removal of the front table user name, the default value to false<! -> <property name="ignoreQualifiersAtRuntime" value="true"/> </table> </context> </generatorConfiguration>
The third step: the implementation of mybatis-generator plugin
The last generation is completed
Note that if multiple time-table mapping file, the contents will be appended to xml , rather than covering
Example of use
XXXXExamlple transfer conditions CRUD
Any of the conditions to achieve a correspondence table for each field in CRUD