Maven multi-module projects use MyBatis Generator, mavenmybatis

Source: Internet
Author: User

Maven multi-module projects use MyBatis Generator, mavenmybatis

Development Environment:

JDK: 8u102

Maven: 3.3.9

MySQL: 5.7.10

MySQL Connector: 5.1.40

IDE: IntelliJ IDEA 2016

MyBatis: 3.4.1

MyBatis Generator: 1.3.5

 

Project case:

Personal blog

 

Project Structure:

  

 

Blog-dao-impl module: it only takes into account multiple implementation layers. Symbolic creation here.

 

Project dependency:

  

 

Database details:

  

 

Blog-dao-api pom. xml details:

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <project xmlns = "http://maven.apache.org/POM/4.0.0" 3 xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" 4 xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId> blog </artifactId> 7 <groupId> pers. kaloquan </groupId> 8 <version> 1.0-SNAPSHOT </version> 9 </parent> 10 <modelVersion> 4.0.0 </modelVersion> 11 12 <artifactId> blog-dao-ap I </artifactId> 13 14 <properties> 15 <! -- MySQL Connector version --> 16 <mysql-connector.version> 5.1.40 </mysql-connector.version> 17 <! -- MyBatis Generator version --> 18 <mybatis-generator.version> 1.3.5 </mybatis-generator.version> 19 20 <! -- Specify the configuration file of MyBatis Generator plug-in --> 21 <plugin. generator. configurationFile >$ {project. basedir} \ src \ main \ resources \ mybatis-generator.xml </plugin. generator. configurationFile> 22 <! -- Whether to override an existing file --> 23 <plugin. generator. overwrite> true </plugin. generator. overwrite> 24 <! -- Generator targetProject root directory --> 25 <generator. project. root> D: \ IDEAProjects \ blog </generator. project. root> 26 <! -- Path of the driver package required by the generator --> 27 <generator. classpath> D :\ Maven repository \ mysql-connector-java \ 5.1.40 \ mysql-connector-java-5.1.40.jar </generator. classpath> 28 29 <! -- Driver Class --> 30 <jdbc. driverClass> com. mysql. jdbc. Driver </jdbc. driverClass> 31 <! -- Link address --> 32 <jdbc. url> jdbc: mysql: // localhost: 3306/blog? CreateDatabaseIfNotExist = true & amp; useSSL = true & amp; serverTimezone = UTC & amp; passwordCharacterEncoding = UTF-8 & amp; characterEncoding = UTF-8 </jdbc. url> 33 <! -- Username --> 34 <jdbc. userId> root </jdbc. userId> 35 <! -- Password --> 36 <jdbc. password> root </jdbc. password> 37 </properties> 38 39 <dependencies> 40 <dependency> 41 <groupId> org. mybatis </groupId> 42 <artifactId> mybatis </artifactId> 43 <version> 3.4.1 </version> 44 </dependency> 45 46 <dependency> 47 <groupId> pers. kaloquan </groupId> 48 <artifactId> blog-model </artifactId> 49 </dependency> 50 </dependencies> 51 52 <build> 53 <plugins> 54 <plugin> 55 <groupId> org. mybatis. generat Or </groupId> 56 <artifactId> mybatis-generator-maven-plugin </artifactId> 57 <version >$ {mybatis-generator.version} </version> 58 <! -- Plug-in configuration --> 59 <configuration> 60 <configurationFile >$ {plugin. generator. configurationFile} </configurationFile> 61 <overwrite >$ {plugin. generator. overwrite} </overwrite> 62 </configuration> 63 <! -- Commands to be executed before Compilation --> 64 <executions> 65 <execution> 66 <id> Generate MyBatis Artifacts </id> 67 <goals> 68 <goal> generate </goal> 69 </goals> 70 </execution> 71 </executions> 72 </plugin> 73 </plugins> 74 </build> 75 </project>View configurations

  

* Note: attribute values declared in properties labels can be used in the mybatis-generator.xml!

 

Mybatis-generator.xml details:

Location: (put it somewhere as needed, and then configure the MyBatis Generator plug-in the pom. xml file of the corresponding project)

    

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <! DOCTYPE generatorConfiguration PUBLIC 3 "-// mybatis.org//DTD MyBatis Generator Configuration 1.0 // EN" 4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 5 <generatorConfiguration> 6 7 <! --!!!! Driver Class Path !!!! --> 8 <classPathEntry location = "$ {generator. classpath}"/> 9 10 <! -- Use MyBatis3Simple, avoid generating unnecessary code --> 11 <context id = "context" targetRuntime = "MyBatis3Simple"> 12 <commentGenerator> 13 <property name = "suppressAllComments" value = "false"/> 14 <property name = "suppressDate" value = "true"/> 15 </commentGenerator> 16 17 <! --!!!! Database deployments !!!! --> 18 <jdbcConnection driverClass = "$ {jdbc. driverClass} "connectionURL =" $ {jdbc. url} "userId =" $ {jdbc. userId} "password =" $ {jdbc. password} "/> 19 20 <javaTypeResolver> 21 <property name =" forceBigDecimals "value =" false "/> 22 </javaTypeResolver> 23 24 <! --!!!! Model invocations !!!! --> 25 <javaModelGenerator targetPackage = "blog. model "targetProject =" $ {generator. project. root} \ blog-model \ src \ main \ java "> 26 <property name =" enableSubPackages "value =" false "/> 27 <property name =" trimStrings "value =" true "/> 28 </javaModelGenerator> 29 30 <! --!!!! Mapper XML Configurations !!!! --> 31 <sqlMapGenerator targetPackage = "mapper" targetProject = "$ {generator. project. root} \ blog-dao-impl \ src \ main \ resources "> 32 <property name =" enableSubPackages "value =" false "/> 33 </sqlMapGenerator> 34 35 <! --!!!! Mapper Interface Configurations !!!! --> 36 <! -- When running MyBatis3Simple, the type can only be "ANNOTATEDMAPPER" or "XMLMAPPER" --> 37 <! -- Annotation configuration is used here, instead of XML configuration --> 38 <javaClientGenerator targetPackage = "blog. dao "targetProject =" $ {generator. project. root} \ blog-dao-api \ src \ main \ java "type =" ANNOTATEDMAPPER "> 39 <property name =" enableSubPackages "value =" false "/> 40 </javaClientGenerator> 41 42 <! --!!!! Table tolerations !!!! --> 43 <table tableName = "user" schema = "blog"> 44 <columnOverride column = "id" property = "id"/> 45 <columnOverride column = "name" property = "name"/> 46 </table> 47 </context> 48 </generatorConfiguration>View configurations

 

The location is not clear or there is something wrong. Please point it out!

 

References:

Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J

MyBatis GeneratorXML Configuration File Reference

Running MyBatis Generator With Maven

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.