SpringBoot与Mybatis-plus整合,代码生成mvc层
一、添加pom依赖
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- mybatisplus与springboot整合 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus--boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<!-- MP 核心库 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.1.8</version>
</dependency>
<!-- 模板引擎 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
<!-- springboot整合mybatis(核心就这一个) -->
<!-- 注意顺序,这个一定要放在最下面 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
二、配置application.yml
# 配置mybatis-plus
mybatis-plus:
# 配置扫描xml
mapper-locations:
- classpath:mapper/*.xml
# 实体扫描,多个package用逗号或者分号分隔
type-aliases-package: com.ahut.entity
global-config:
# 逻辑删除配置
logic-delete-value: 0
logic-not-delete-value: 1
sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
三、代码生成主方法
package com.example.mall.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;
/**
*
* @ClassName: CodeGeneration
* @Description: 代码生成器
*/
public class CodeGeneration {
public static void main(String[] args) {
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir("D://code");
gc.setFileOverride(true);
gc.setActiveRecord(false);// 不需要ActiveRecord特性的请改为false
gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(false);// XML columList
gc.setAuthor("wu");// 作者
// 自定义文件命名,注意 %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("123456");
dsc.setUrl("jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf8&useSSL=false");
mpg.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setTablePrefix(new String[] { "mmall_" });// 此处可以修改为您的表前缀
strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
strategy.setInclude(new String[] { "mmall_cart" }); // 需要生成的表
strategy.setSuperServiceClass(null);
strategy.setSuperServiceImplClass(null);
strategy.setSuperMapperClass(null);
mpg.setStrategy(strategy);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.example.mall");
pc.setController("controller");
pc.setService("service");
pc.setServiceImpl("serviceImpl");
pc.setMapper("mapper");
pc.setEntity("pojo");
pc.setXml("xml");
mpg.setPackageInfo(pc);
// 执行生成
mpg.execute();
}
}
SpringBoot与Mybatis-plus整合,代码生成mvc层的更多相关文章
- SpringBoot+SpringMVC+MyBatis快速整合搭建
作为开发人员,大家都知道,SpringBoot是基于Spring4.0设计的,不仅继承了Spring框架原有的优秀特性,而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程.另外Spr ...
- springboot+springmvc+mybatis项目整合
介绍: 上篇给大家介绍了ssm多模块项目的搭建,在搭建过程中spring整合springmvc和mybatis时会有很多的东西需要我们进行配置,这样不仅浪费了时间,也比较容易出错,由于这样问题的产生, ...
- Springboot与MyBatis简单整合
之前搭传统的ssm框架,配置文件很多,看了几天文档才把那些xml的逻辑关系搞得七七八八,搭起来也是很麻烦,那时我完全按网上那个demo的版本要求(jdk和tomcat),所以最后是各种问题没成功跑起来 ...
- SpringBoot和Mybatis的整合
这里介绍两种整合SpringBoot和Mybatis的模式,分别是“全注解版” 和 “注解xml合并版”. 前期准备开发环境 开发工具:IDEAJDK:1.8技术:SpringBoot.Maven.M ...
- IntelliJ IDEA 2017版 spring-boot与Mybatis简单整合
一.编译器建立项目 参考:http://www.cnblogs.com/liuyangfirst/p/8372291.html 二.代码编辑 1.建立数据库 /* Navicat MySQL Data ...
- springboot对mybatis的整合
1. 导入依赖 首先新建一个springboot项目,勾选组件时勾选Spring Web.JDBC API.MySQL Driver pom.xml配置文件导入依赖 <!--mybatis-sp ...
- SpringBoot系列——MyBatis整合
前言 MyBatis官网:http://www.mybatis.org/mybatis-3/zh/index.html 本文记录springboot与mybatis的整合实例:1.以注解方式:2.手写 ...
- SpringBoot与SpringDateJPA和Mybatis的整合
一.SpringBoot与SpringDateJPA的整合 1-1.需求 查询数据库---->得到数据------>展示到页面上 1-2.整合步骤 1-2-1.创建SpringBoot工程 ...
- 30分钟带你了解Springboot与Mybatis整合最佳实践
前言:Springboot怎么使用想必也无需我多言,Mybitas作为实用性极强的ORM框架也深受广大开发人员喜爱,有关如何整合它们的文章在网络上随处可见.但是今天我会从实战的角度出发,谈谈我对二者结 ...
随机推荐
- Django框架-模板层
Django框架-模板层 一.模板语法传值 1.验证是否python所有的数据类型都可以传递到前端 locals()的妙用:该方法虽然好用,但是在某些情况下会造成资源的浪费 结论:整型.浮点型.字符串 ...
- 【HTTP与HTTPS的区别】
目录 一.HTTP和HTTPS的基本概念 二.HTTP与HTTPS有何区别 三.HTTP与HTTPS的工作原理 四.HTTPS的优缺点 五.HTTP切换至HTTPS "超文本传输协议,即HT ...
- 基于selenium+Python3.7+yaml+Robot Framework的UI自动化测试框架
前端自动化测试框架 项目说明 本框架是一套基于selenium+Python3.7+yaml+Robot Framework而设计的数据驱动UI自动化测试框架,Robot Framework 作为执行 ...
- Linux运维工作总结教训
Linux运维一定要知道的六类好习惯和23个教训,避免入坑!从事运维三年半,遇到过各式各样的问题,数据丢失,网站挂马,误删数据库文件,黑客攻击等各类问题. 今天简单整理一下,分享给各位小伙伴. 一.线 ...
- linux日常运维工作
Linux的使用环境也日趋成熟,各种开源产品络绎不绝,大有百花齐放的盛景,那么当Linux落地企业,回归工作时,我们还要面对这Linux运维方面的诸多问题,今天我们特意组织一场有关Linux 在企业运 ...
- allegro 16.6 铜皮显示问题
Setup-->User Preference-->display-->opengl-->staic-shapes_fill_solid打勾.可以将栅格铜皮改为实铜, Setu ...
- php相关问题学习(以备面试)
1.原味地址:[ http://www.yiichina.com/tutorial/57 ] 注:本文转自 http://www.icultivator.com/p/5535.html 整理了一份PH ...
- 在虚拟机安装centos7
因为工作需要,要经常用到虚拟机,以I前老让别人给装,可是老问人家也不好,自己整理一份比较适合小白用的教程,有点繁琐: 一.工具:VMware CentOS7 的 ISO 文件 二.开始安装 ...
- Block Chain Learning Notes
区块链是什么 区块链技术是由比特币创造的,本文也将从比特币开始进行引导,一步一步告诉大家什么是区块链.如果你想立马知道区块链是什么,也可以直接转到文章末尾的区块链定义. 区块链,可能是当下最有前景又充 ...
- as(android studio)的初次使用
链接:https://blog.csdn.net/qq_28808627/article/details/50058805