mybatisplus自動生成コード(3.3.2バージョン)古いバージョンは異なります

29904 ワード

公式サイト
1、使用したmaven依存

    <dependency>
        <groupId>org.junit.jupitergroupId>
        <artifactId>junit-jupiter-engineartifactId>
    dependency>
    <dependency>
        <groupId>com.baomidougroupId>
        <artifactId>mybatis-plus-generatorartifactId>
        <version>3.3.2version>
    dependency>
    <dependency>
        <groupId>org.apache.velocitygroupId>
        <artifactId>velocity-engine-coreartifactId>
        <version>2.2version>
    dependency>

2、公式サイトが提供する怠け者の直接生成類
mybatisplus 3–mysqlバージョン
package com.SpringBoot.util;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import org.junit.jupiter.api.Test;

/**
 * 

* *

* * @author K * @date 2017/12/18 */
public class GeneratorServiceEntity { @Test public void generateCode() { String packageName = "com.SpringBoot.*"; boolean serviceNameStartWithI = true;//user -> UserService, true: user -> IUserService generateByTables(serviceNameStartWithI, packageName, "msg_log"); } private void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) { GlobalConfig config = new GlobalConfig(); String dbUrl = "jdbc:mysql://localhost:3306/SpringBoot?serverTimezone=UTC"; DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL) .setUrl(dbUrl) .setUsername("root") .setPassword("root") .setDriverName("com.mysql.cj.jdbc.Driver"); StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig .setCapitalMode(true) .setEntityLombokModel(false) // .setDbColumnUnderline(true) .setNaming(NamingStrategy.underline_to_camel) .setInclude(tableNames);// , config.setActiveRecord(false) .setAuthor(" ") .setOutputDir("D:\\Job\\GenerateCode") .setFileOverride(true); if (!serviceNameStartWithI) { config.setServiceName("%sService"); } new AutoGenerator().setGlobalConfig(config) .setDataSource(dataSourceConfig) .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig() .setParent(packageName) // .setController("controller") // .setEntity("entity") .setController("web") .setEntity("pojo.bo") ).execute(); } private void generateByTables(String packageName, String... tableNames) { generateByTables(true, packageName, tableNames); } }

mybatisplus 2-oracleバージョン
package com.SpringBoot.common;


import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import org.junit.jupiter.api.Test;

/**
 * 

* *

* * @author K * @date 2017/12/18 */
public class GeneratorServiceEntity { @Test public void generateCode() { String packageName = "com.SpringBoot.*"; boolean serviceNameStartWithI = true;//user -> UserService, true: user -> IUserService generateByTables(serviceNameStartWithI, packageName, "test"); } private void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) { GlobalConfig config = new GlobalConfig(); String dbUrl = "jdbc:oracle:thin:@localhost:1521:orcl"; DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.ORACLE) .setUrl(dbUrl) .setUsername("test") .setPassword("test") .setDriverName("oracle.jdbc.OracleDriver"); StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig .setCapitalMode(true) .setEntityLombokModel(false) // .setDbColumnUnderline(true) .setNaming(NamingStrategy.underline_to_camel) .entityTableFieldAnnotationEnable(true)// .setInclude(tableNames);// , config.setActiveRecord(false) .setAuthor(" ") .setOutputDir("D:\\Job\\project") .setFileOverride(true); if (!serviceNameStartWithI) { config.setServiceName("%sService"); } new AutoGenerator().setGlobalConfig(config) .setDataSource(dataSourceConfig) .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig() .setParent(packageName) // .setController("web") // .setEntity("entity" ) .setController("web") .setEntity("pojo.bo") ).execute(); } private void generateByTables(String packageName, String... tableNames) { generateByTables(true, packageName, tableNames); } }