Use Mybatis to automatically generate our dao interfaces, mapper files and entity classes.
1, pom.xml dependent on:
<dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies>
2, pom.xml plugins:
<build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <!--要创建的 generator 配置文件路径--> <configurationFile>generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin> </plugins> </build>
3, the most important generatorConfig.xml file:
<? 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 > ! <- 1. modify absolute path connected to its local jar package MySQL (driving packets) -> < classpathentry LOCATION =" D: \ Tools \ MySQL- 5.1.39.jar-java-Connector " /> < context ID =" context " > < commentGenerator > <-! encoded file generated java -> <property name="javaFileEncoding"value = "UTF-. 8" /> < Property name = "suppressAllComments" value = "to false" /> < Property name = "suppressDate" value = "to true" /> </ commentGenerator > <-! 2. specified database drive, connection address, user name, password, (similar to the data source) -> < JdbcConnection driverClass = "com.mysql.jdbc.Driver" the connectionURL = "JDBC: MySQL: /// EDA to true useUnicode = & amp; & amp to false useSSL =? ; = UTF-characterEncoding. 8 " the userId =" the root " password="root" /> <!--3. The entity class generated location (absolute need to specify a package name and address) (address can be customized, but does not automatically create a path exists, using Maven generated in the target directory, created automatically) -> < javaModelGenerator targetPackage = "com.jieku.model" targetProject = "D: \ IdeaProjects \ trymp_springboot \ mybatis_gen \ src \ main \ the Java" > < Property name = "enableSubPackages" value = "to true" /> <-! If true, MBG will be based generating a schema catalog and sub-packets. If false it will directly targetPackage property. The default is false -> < Property name = "trimStrings" value = "to true" /> <-! When the database fields using CHAR, with spaces may need to go to space -> > <! - 4. Generated files Mapper (xxxMapper.xml) -> < sqlMapGenerator targetPackage = "Mapper" targetProject = "D: \ IdeaProjects \ trymp_springboot \ mybatis_gen \ the src \ main \ Resources" /> <! - 5. generate document Dao (interface) may be configured type = "XMLMAPPER" generated dao xml implemented -> < javaClientGenerator targetPackage = "com.jieku.dao" targetProject = "D: \ IdeaProjects \ trymp_springboot \ mybatis_gen \ the src \ main \ Java " type =" XMLMAPPER " /> <-! 6. The table specifies all -> < table tableName ="% "/> <!-- 7. New Maven command, says: mybatis-generator:generate -e --> </context> </generatorConfiguration>
4, New Maven command
5, execute Maven command:
6, implementation of the results
At this point, generate complete.