<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" > <generatorConfiguration> <!-- 引入配置文件 --> <properties resource="jdbc.properties"/> <!-- 指定数据连接驱动jar地址 --> <classPathEntry location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" /> <!-- 一个数据库一个context --> <context id="FCRMTables"> <!-- 注释 --> <commentGenerator > <property name="suppressAllComments" value="true"/><!-- 是否取消注释 --> <property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳--> </commentGenerator> <!-- jdbc连接 --> <jdbcConnection driverClass="${driverClassName}" connectionURL="${url}" userId="${username}" password="${password}" /> <!-- 类型转换 --> <javaTypeResolver> <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) --> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 生成实体类的包名和位置 注意targetProject的值为实体类放在工程中具体位置的相对路径,--> <javaModelGenerator targetPackage="com.qlm.entity" targetProject="src/main/java" > <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> <property name="enableSubPackages" value="true"/> <!-- 是否针对string类型的字段在set的时候进行trim调用 --> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成的SQLMapper映射文件包名和位置 --> <sqlMapGenerator targetPackage="mybatisMapper" targetProject="src/main/resources" > <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置,这里配置将生成的dao类放在me.gacl.dao这个包下 --> <javaClientGenerator targetPackage="com.qlm.dao" targetProject="src/main/java" type="XMLMAPPER" > <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 配置表信息 --> <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample 是否生成 example类 --> <!-- 更改tableName和domainObjectName就可以 --> <table schema="qlm" tableName="tb_qlm_admin" domainObjectName="Admin" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"> </table> </context> </generatorConfiguration>
jdbc.properties文件如下
driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/qlm?autoReconnect=true&useUnicode=true&characterEncoding=utf-8 username=root password=root
运行-->Run As -->Maven build-->Goals填写mybatis-generator:generate--Run
或者 直接运行 mvn mybatis-generator:generate -e
根据命令 生成不同环境的 orm包
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>xxx</groupId> <artifactId>xxx</artifactId> <version>1.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.6</version> </dependency> </dependencies> <!-- <distributionManagement> <repository> <id>nexus</id> <url>http://47.97.159.47:8081/repository/maven-releases/</url> </repository> </distributionManagement>--> <profiles> <profile> <id>prod</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <!--java版本--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <!--mybatis 生成代码--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.6</version> <configuration> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <phase>deploy</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.6</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.21</version> </dependency> <dependency> <groupId>com.itfsw</groupId> <artifactId>mybatis-generator-plugin</artifactId> <version>1.3.8</version> </dependency> </dependencies> </plugin> </plugins> </build> </profile> <profile> <id>debug</id> <build> <plugins> <!--java版本--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <!--mybatis 生成代码--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.6</version> <configuration> <configurationFile>src/main/resources/generatorConfig-debug.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <phase>deploy</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.6</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.21</version> </dependency> <dependency> <groupId>com.itfsw</groupId> <artifactId>mybatis-generator-plugin</artifactId> <version>1.3.8</version> </dependency> </dependencies> </plugin> </plugins> </build> </profile> </profiles> </project>
执行命令
mvn mybatis-generator:generate -e -P debug mvn mybatis-generator:generate -e -P pord
标签:maven,配置文件,generator,1.3,generatorConfiguration,解读,mybatis,org,true From: https://www.cnblogs.com/qianxiaoPro/p/17239520.html