Mybatis Plus 逆向工程生成mapper、model、service、controller

package com.ftvalue.poppy;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
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.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.HashMap;
import java.util.Map;

public class MybatisPlusGenerator {
    /**
     * 

* MySQL 生成演示 *

*/ public static void main(String[] args) { AutoGenerator autoGenerator = new AutoGenerator(); System.out.println("开始执行=="); //全局配置 GlobalConfig globalConfig = new GlobalConfig(); globalConfig.setOutputDir("D:\\work\\ifpay-poppy\\poppy-boss-server\\src\\main"); globalConfig.setFileOverride(false); globalConfig.setActiveRecord(true); globalConfig.setEnableCache(false);// XML 二级缓存 globalConfig.setBaseResultMap(true);// XML ResultMap globalConfig.setBaseColumnList(false);// XML columList globalConfig.setAuthor("admin"); //生成文件名: globalConfig.setXmlName("%sMapper"); globalConfig.setMapperName("%sMapper"); globalConfig.setServiceName("%sService"); globalConfig.setServiceImplName("%sImpl"); globalConfig.setControllerName("%sController"); autoGenerator.setGlobalConfig(globalConfig); // 数据源配置 DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL); dataSourceConfig.setTypeConvert(new MySqlTypeConvert(){ @Override public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) { return super.processTypeConvert(globalConfig, fieldType); } }); dataSourceConfig.setDriverName("com.mysql.jdbc.Driver"); dataSourceConfig.setUsername("dba"); dataSourceConfig.setPassword("dba"); dataSourceConfig.setUrl("jdbc:mysql://ip:3306//数据库名称?zeroDateTimeBehavior=convertToNull&allowMultiQueries=true"); autoGenerator.setDataSource(dataSourceConfig); // 策略配置 StrategyConfig strategyConfig = new StrategyConfig(); // strategyConfig.setCapitalMode(true); // 全局大写命名 ORACLE 注意 strategyConfig.setTablePrefix(new String[] { "t_drp_", "qrtz_", "t_sys"});// 此处可以修改为您的表前缀 strategyConfig.setNaming(NamingStrategy.underline_to_camel); strategyConfig.setInclude(new String[] { "t_drp_product" }); // 需要生成的表 autoGenerator.setStrategy(strategyConfig); // 包配置 PackageConfig packageConfig = new PackageConfig(); packageConfig.setParent(null); packageConfig.setEntity("java.com.ftvalue.poppy.repository.model"); packageConfig.setMapper("java.com.ftvalue.poppy.repository.mapper"); packageConfig.setController("java.com.ftvalue.poppy.controller"); packageConfig.setService("java.com.ftvalue.poppy.service"); packageConfig.setServiceImpl("java.com.ftvalue.poppy.service.impl"); packageConfig.setXml("resources.mapper"); autoGenerator.setPackageInfo(packageConfig); // 注入自定义配置,可以在 VM 中使用 cfg.abc 【可无】 InjectionConfig injectionConfig = new InjectionConfig() { @Override public void initMap() { Map map = new HashMap(); map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp"); this.setMap(map); } }; autoGenerator.setCfg(injectionConfig); // 执行生成 autoGenerator.execute(); // 打印注入设置【可无】 System.err.println(autoGenerator.getCfg().getMap().get("abc")); } }

你可能感兴趣的:(基础工具,spring-boot)