mybatisplus自动生成代码(3.3.2版本)旧的版本会有不同

官网说明

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、官网提供的懒人直达生成类

mybatisplus3–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); } }

mybatisplus2—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); } }

你可能感兴趣的:(mybatisplus)