标签:rip 生成文件 oid oge enable etc 使用 auth camel
使用mybatis-plus可以自动帮我们生成通用的 controller,service,dao,mapper
<!-- mybatisplus与springboot整合 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatisplus-spring-boot-starter</artifactId> <version>1.0.5</version> </dependency> <!-- MP 核心库 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>2.1.8</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <!-- 模板引擎 代码生成 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.7</version> </dependency>
# 配置mybatis-plus # 配置扫描xml mybatis-plus.mapper-locations=classpath:mapper/*.xml # 实体扫描,多个package用逗号或者分号分隔 mybatis-plus.type-aliases-package=com.example.model #逻辑删除配置 mybatis-plus.global-config.sql-injector=com.baomidou.mybatisplus.mapper.LogicSqlInjector #配置逻辑删除字段为1是删除 mybatis-plus.global-config.logic-delete-value=1 #配置逻辑删除字段为0是未删除 mybatis-plus.global-config.logic-not-delete-value=0
CodeGeneration.java
package com.example.demo;
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;
/**
*
* @ClassName: CodeGeneration
* @Description: 代码生成器
* @author yux
* @date 2018年1月25日 下午2:55:14
*/
public class CodeGeneration {
/**
*
* @Title: main
* @Description: 生成
* @param args
*/
public static void main(String[] args) {
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir("D://"); //输出文件路径
gc.setFileOverride(true);
gc.setActiveRecord(false);// 不需要ActiveRecord特性的请改为false
gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(false);// XML columList
gc.setAuthor("yux");// 作者
// 自定义文件命名,注意 %s 会自动填充表实体属性!
gc.setControllerName("%sController");
gc.setServiceName("%sService");
gc.setServiceImplName("%sServiceImpl");
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("root");
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/springbootdemo");
mpg.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// strategy.setTablePrefix(new String[] { "sys_" });// 此处可以修改为您的表前缀
strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
strategy.setInclude(new String[] { "user_info" }); // 需要生成的表
strategy.setSuperServiceClass(null);
strategy.setSuperServiceImplClass(null);
strategy.setSuperMapperClass(null);
mpg.setStrategy(strategy);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.example.demo");
pc.setController("controller");
pc.setService("service");
pc.setServiceImpl("service.impl");
pc.setMapper("dao");
pc.setEntity("model");
pc.setXml("xml");
mpg.setPackageInfo(pc);
// 执行生成
mpg.execute();
}
}
右击run CodeGeneration main();生成文件,然后放到你的项目中。
@MapperScan("com.example.demo.dao")
使用mybatis-plus+自动代码生成时候必需把第一章讲的MyBatisConfigurer.java的类删掉,否则报错!!!!!
(八)SpringBoot使用mybatis-plus+自动代码生成
标签:rip 生成文件 oid oge enable etc 使用 auth camel
原文地址:https://www.cnblogs.com/yui66/p/9621115.html