赞
踩
com.mysql.jdbc.Driver
<build> <plugins> <!-- mybatis generator 自动生成代码插件 --> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.4.0</version> <configuration> <!--config文件位置--> <configurationFile>src/main/resources/generator-config-x.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.22</version> </dependency> </dependencies> </plugin> </plugins>
src/main/resources/generator-config-x.xml
文件,参考内容如下:<?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> <context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat"> <!-- 自动检查关键字,为关键字增加反引号 --> <property name="autoDelimitKeywords" value="true"/> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <!--覆盖生成XML文件--> <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" /> <!-- 生成的实体类添加toString()方法 --> <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/> <!-- 不生成注释 --> <commentGenerator> <property name="suppressAllComments" value="true"/> </commentGenerator> <!-- 配置mysql8数据源,需要根据自己的项目修改 --> <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/xxx?serverTimezone=Asia/Shanghai&characterEncoding=UTF-8" userId="xxx" password="xxx"> </jdbcConnection> <!-- domain类的位置 targetProject是相对pom.xml的路径--> <javaModelGenerator targetProject="../相应的子模块名称/src/main/java" targetPackage="com.yang.train.x.domain"/> <!-- mapper xml的位置 targetProject是相对pom.xml的路径 --> <sqlMapGenerator targetProject="../相应的子模块名称/src/main/resources" targetPackage="mapper"/> <!-- mapper类的位置 targetProject是相对pom.xml的路径 --> <javaClientGenerator targetProject="../相应的子模块名称/src/main/java" targetPackage="com.yang.train.x.mapper" type="XMLMAPPER"/> <table tableName="x" domainObjectName="x"/> <!--<table tableName="passenger" domainObjectName="Passenger"/>--> <!--<table tableName="ticket" domainObjectName="Ticket"/>--> </context> </generatorConfiguration>
[INFO] Scanning for projects... [INFO] [INFO] ----------------------< com.yang:train-generator >---------------------- [INFO] Building train-generator 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- mybatis-generator-maven-plugin:1.4.0:generate (default-cli) @ train-generator --- [INFO] Connecting to the Database [INFO] Introspecting table x [INFO] Generating Example class for table x [INFO] Generating Record class for table x [INFO] Generating Mapper Interface for table x [INFO] Generating SQL Map for table x [INFO] Saving file xMapper.xml [INFO] Saving file xExample.java [INFO] Saving file x.java [INFO] Saving file xMapper.java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.204 s [INFO] Finished at: 2024-02-07T12:30:58+08:00 [INFO] ------------------------------------------------------------------------
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。