一、添加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层的更多相关文章

  1. SpringBoot+SpringMVC+MyBatis快速整合搭建

    作为开发人员,大家都知道,SpringBoot是基于Spring4.0设计的,不仅继承了Spring框架原有的优秀特性,而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程.另外Spr ...

  2. springboot+springmvc+mybatis项目整合

    介绍: 上篇给大家介绍了ssm多模块项目的搭建,在搭建过程中spring整合springmvc和mybatis时会有很多的东西需要我们进行配置,这样不仅浪费了时间,也比较容易出错,由于这样问题的产生, ...

  3. Springboot与MyBatis简单整合

    之前搭传统的ssm框架,配置文件很多,看了几天文档才把那些xml的逻辑关系搞得七七八八,搭起来也是很麻烦,那时我完全按网上那个demo的版本要求(jdk和tomcat),所以最后是各种问题没成功跑起来 ...

  4. SpringBoot和Mybatis的整合

    这里介绍两种整合SpringBoot和Mybatis的模式,分别是“全注解版” 和 “注解xml合并版”. 前期准备开发环境 开发工具:IDEAJDK:1.8技术:SpringBoot.Maven.M ...

  5. IntelliJ IDEA 2017版 spring-boot与Mybatis简单整合

    一.编译器建立项目 参考:http://www.cnblogs.com/liuyangfirst/p/8372291.html 二.代码编辑 1.建立数据库 /* Navicat MySQL Data ...

  6. springboot对mybatis的整合

    1. 导入依赖 首先新建一个springboot项目,勾选组件时勾选Spring Web.JDBC API.MySQL Driver pom.xml配置文件导入依赖 <!--mybatis-sp ...

  7. SpringBoot系列——MyBatis整合

    前言 MyBatis官网:http://www.mybatis.org/mybatis-3/zh/index.html 本文记录springboot与mybatis的整合实例:1.以注解方式:2.手写 ...

  8. SpringBoot与SpringDateJPA和Mybatis的整合

    一.SpringBoot与SpringDateJPA的整合 1-1.需求 查询数据库---->得到数据------>展示到页面上 1-2.整合步骤 1-2-1.创建SpringBoot工程 ...

  9. 30分钟带你了解Springboot与Mybatis整合最佳实践

    前言:Springboot怎么使用想必也无需我多言,Mybitas作为实用性极强的ORM框架也深受广大开发人员喜爱,有关如何整合它们的文章在网络上随处可见.但是今天我会从实战的角度出发,谈谈我对二者结 ...

随机推荐

  1. 吴裕雄 python 机器学习——半监督学习LabelSpreading模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import metrics from sklearn import d ...

  2. centos 7 添加swap

    [root@lab01 /]# cd / [root@lab01 /]# + records in + records out bytes ( MB/s [root@lab01 /]# free -m ...

  3. 陆金所退出市场,我说:趁现在,抓紧离开P2P市场,你赞同吗?

    编辑 | 于斌 出品 | 于见(mpyujian) 18日,也就是前天,陆金所退出P2P市场的消息就像颗"重磅炸弹"一样,一波激起千层浪,陆金所作为全国最大财富平台之一,这次退出, ...

  4. sublime-text3 安装 emmet 插件

    下载sublime,http://www.sublimetext.com/ 安装package control :https://packagecontrol.io/ins... 这个地址需要翻墙,访 ...

  5. css 溢出滚动条显示,修改滚动条样式

    文本或者内容溢出滚动条显示: a/横纵都出滚动条:css添加属性{overflow:auto;} b/横向滚动条:css添加属性{overflow-x:auto;} c/纵向滚动条:css添加属性{o ...

  6. Linux上临时路由、永久路由配置

    Linux下查看路由条目 查看路由表命令 route -n 示例 [root@cobbler_vm ~]# route -n Kernel IP routing table Destination G ...

  7. 读书笔记, Python - python-tricks-buffet-awesome-features

    To be a Pythonista 1. assert syntax: assert expression1 [",", expression2] 大致相当于 if __debu ...

  8. 一些基础但有趣的shell脚本

    一.打印9*9乘法表 #!/bin/bash for i in `seq 9` do for j in `seq $i` do echo -n "$i*$j=$[i*j]" don ...

  9. github是什么,有什么用

    转载连接:https://blog.csdn.net/obkoro1/article/details/68066441 写在前面:关于github的文章我已经写了两篇了,关于github个人网站搭建和 ...

  10. Android学习05

    AlertDialog(对话框) 它也是其他 Dialog的的父类!比如ProgressDialog,TimePickerDialog等,而AlertDialog的父类是:Dialog! AlertD ...