Springboot 整合 MyBatisPlus[详细过程]
Springboot 整合 MyBatisPlus[详细过程]
提要
这里已经将Springboot环境创建好 这里只是整合MyBatis过程
引入Maven依赖
添加MyBatisPlus启动依赖,添加mysql-connector-java依赖
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
<!-- mybatis-plus代码生成器 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.1.tmp</version>
</dependency>
<!-- mysql连接 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
添加application.yml配置
mybatis-plus配置项
mybatis-plus:
# xml文件路径
mapper-locations: classpath:mapper/*.xml
# 实体类路径
type-aliases-package: com.数据库表对应的实体类的路径
configuration:
# 驼峰转换
map-underscore-to-camel-case: true
# 是否开启缓存
cache-enabled: false
# 打印sql
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 全局配置
global-config:
# 数据库字段驼峰下划线转换
db-column-underline: true
# id自增类型(数据库id自增)
id-type: 0
mysql配置项
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: stone
url: jdbc:mysql://ip:3306/库名?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false
添加数据库对应实体类
@Data
@TableName("class_table")
public class ClassPojo {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField(value = "class_name")
private String className;
}
添加Mapper文件
@Mapper
public interface ClassMapper extends BaseMapper<ClassPojo> {
}
添加Service接口
public interface ClassVoService extends IService<ClassPojo> {
String getClassName(Long id);//自定义方法
}
添加Service实现类
@Component
public class ClassVoServiceImpl extends ServiceImpl<ClassMapper, ClassPojo> implements ClassVoService {
public String getClassName(Long id){
ClassPojo byId = getById (id);
return byId.getClassName ();
}
}
添加Controller
@RestController
@RequestMapping("/demo")
public class ExcelController {
@GetMapping("/getbyid")
public String getbyid(){
return classVoService.getClassName (1l);
}
}
补充对应表结构
CREATE TABLE `class_table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '课程id不能为空主键',
`class_name` varchar(255) NOT NULL COMMENT '课程名称',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
表数据如下
| id | class_name |
|---|---|
| 1 | 语文 |
| 2 | 数学 |
Springboot 整合 MyBatisPlus[详细过程]的更多相关文章
- 关于springboot整合的详细过程
Spring-boot http://tengj.top/2017/04/24/springboot0/
- SpringBoot整合Mybatis-Plus
这篇文章介绍一个SpringBoot整合Mybatis-Plus,提供一个小的Demo供大家参考. 已经很久没有写文章了,最近家里有点事刚刚处理完,顺便也趁机休息了一段时间.刚回到公司看了一下码云,发 ...
- SpringBoot整合MyBatisPlus配置动态数据源
目录 SpringBoot整合MyBatisPlus配置动态数据源 SpringBoot整合MyBatisPlus配置动态数据源 推文:2018开源中国最受欢迎的中国软件MyBatis-Plus My ...
- SpringBoot整合Mybatis-plus实现增删查改
今天给大家分享一下SpringBoot整合Mybatis-plus的增删查改案例. pom.xml <?xml version="1.0" encoding="UT ...
- SpringBoot 整合 MyBatis-Plus 入门体验
一.前言 本文小编将基于 SpringBoot 整合 MyBatis-Plus , MyBatis-Plus 是一个 MyBatis 的增强工具,在 MyBatis 的基础上做增强并且不改变原本功能 ...
- 5、SpringBoot整合之SpringBoot整合MybatisPlus
SpringBoot整合MybatisPlus 目录(可点击直接跳转,但还是建议按照顺序观看,四部分具有一定的关联性): 实现基础的增删改查 实现自动填充功能 实现逻辑删除 实现分页 首先给出四部分完 ...
- 实践丨SpringBoot整合Mybatis-Plus项目存在Mapper时报错
摘要:在SpringBoot运行测试Mybatis-Plus测试的时候报错的问题分析与修复 本文分享自华为云社区<SpringBoot整合MybatisPlus项目存在Mapper时运行报错的问 ...
- SpringBoot整合Elasticsearch详细步骤以及代码示例(附源码)
准备工作 环境准备 JAVA版本 java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121 ...
- SpringBoot整合Swagger2详细教程
1. 简介 随着前后端分离开发模式越来越流行,编写接口文档变成了开发人员非常头疼的事.而Swagger是一个规范且完整的web框架,用于生成.描述.调用可视化的RESTful风格的在线接口文档,并 ...
随机推荐
- 面试问题之C++语言:mutable关键字
转载于:https://www.cnblogs.com/xkfz007/articles/2419540.html mutable关键字 mutable的中文意思是"可变的,易变的" ...
- Log4j使用(转)
from:http://www.cnblogs.com/ITtangtang/p/3926665.html 一.Log4j简介Log4j有三个主要的组件:Loggers(记录器),Appenders ...
- 数仓建模—OneID
今天是我在上海租房的小区被封的第三天,由于我的大意,没有屯吃的,外卖今天完全点不到了,中午的时候我找到了一包快过期的肉松饼,才补充了1000焦耳的能量.但是中午去做核酸的时候,我感觉走路有点不稳,我看 ...
- Markdown语法2
二 . 低频使用的语法 下面是相对用得少的markdown语法,但也值得学习学习. 10.区块(块引用) 要创建块引用,请在段落前添加一个 > 符号: 块引用支持多段落: 块引用支持嵌套,即引 ...
- 【C/C++】C语言基础知识【第二版】
基础语法 输出语句 #include <stdio.h> int main(void) { printf("-------分界线1------- \n"); print ...
- DIANA算法
DIANA算法 DIANA算法示例 DIANA算法练习
- 程序人生:织梦dedecms后台/会员验证码关闭
dedecms默认是所有的功能几乎只要用到验证码的地方我们都需要验证的,如果要关闭一些验证功能我们可以参考下面的教程,这里介绍了关闭后台,留言板,会员系统等验证码功能关闭了.提示:支持DedeCMS ...
- 【Android开发】Android 颜色透明度换算
透明度 透明度分为256阶(0-255),计算机上用16进制表示为(00-ff). 透明就是0阶,不透明就是255阶,如果50%透明就是127阶(256的一半当然是128,但因为是从0开始,所以实际上 ...
- 引用nodejs的url模块实现url路由功能
我们在本地创建服务器之后需要写不同的后缀名来访问同一个站点的不同页面,如果不实现路由功能.则每次访问localhost:3000 不论后面写什么 比如localhost:3000/index.loc ...
- jupyter notebook 调用.py文件
方法1.利用 %run xx.py 直接运行得出结果. 方法2:利用 %load xx.py 载入代码再点击Run运行,这种方法的好处是可以方便修改代码. 说明: Jupyter Notebook中以 ...