使用Java代码配置MyBatis Generator
2021-05-14 09:28
标签:sys target maven dbcc direct catch 数据库 host lse 使用MyBatis Generator生成器时,有时候没办法使用xml形式的配置文件,比如将Maven项目设置成pom打包方式( 这个时候就会用到纯Java代码的MyBatis Generator配置,直接贴配置代码: 然后就是把MyBatis Generator调用过程中原本读取xml配置文件的地方换掉就可以了: 最后把xml形式的配置也贴上,说不定能帮到某些同学: 如果对你有帮助,请记得点个【推荐】! Talk is cheap, show me the code! Bye. 使用Java代码配置MyBatis Generator 标签:sys target maven dbcc direct catch 数据库 host lse 原文地址:https://www.cnblogs.com/xuruiming/p/13124609.html build>
resources>
resource>
directory>src/main/javadirectory>
includes>
include>**/*.propertiesinclude>
include>**/*.ymlinclude>
include>**/*.xmlinclude>
includes>
resource>
resource>
directory>src/main/resourcesdirectory>
includes>
include>**/*.propertiesinclude>
include>**/*.ymlinclude>
include>**/*.xmlinclude>
includes>
resource>
resources>
build>
import org.mybatis.generator.config.*;
/**
* 基于Java代码的MBG配置
* Maven打包方式为POM的项目或模块(
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.util.ArrayList;
import java.util.List;
/**
* MyBatisGenerator代码生成器Java调用程序
*
* @author 707669522@qq.com
* @since 2020-06-13
*/
public class GeneratorRunner {
public static void main(String[] args) {
try {
List
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="simple" targetRuntime="MyBatis3Simple">
property name="javaFileEncoding" value="UTF-8"/>
plugin type="com.xgclassroom.generator.GeneratorPlugin">plugin>
commentGenerator>
property name="suppressAllComments" value="true"/>
commentGenerator>
jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/customer_center?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false"
userId="xurm" password="1qaz@WSX">
property name="nullCatalogMeansCurrent" value="true">property>
property name="remarksReporting" value="true">property>
property name="useInformationSchema" value="true">property>
jdbcConnection>
javaModelGenerator targetPackage="com.xgclassroom.model" targetProject="customer/src/main/java"/>
sqlMapGenerator targetPackage="com.xgclassroom.mapper" targetProject="customer/src/main/java">sqlMapGenerator>
javaClientGenerator type="XMLMAPPER" targetPackage="com.xgclassroom.mapper"
targetProject="customer/src/main/java"/>
table tableName="%">
generatedKey column="id" sqlStatement="JDBC"/>
table>
context>
generatorConfiguration>