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风格的在线接口文档,并 ...
随机推荐
- IDEA terminal无法从vim的编辑模式转换为命令模式
Git 修改最后一次的commit历史记录:https://www.baidu.com/link?url=2WF8yFd0iBuVmXLWfutmSoXa12K9D143e_B0A3PTYYHEP9r ...
- 你如何理解 Spring Boot 中的 Starters?
Starters可以理解为启动器,它包含了一系列可以集成到应用里面的依赖包,你可以一站式集成 Spring 及其他技术,而不需要到处找示例代码和依赖包.如你想使用 Spring JPA 访问数据库,只 ...
- 有哪些不同类型的IOC(依赖注入)方式?
构造器依赖注入:构造器依赖注入通过容器触发一个类的构造器来实现的,该类有一系列参数,每个参数代表一个对其他类的依赖. Setter方法注入:Setter方法注入是容器通过调用无参构造器或无参stati ...
- @Required 注解 ?
这个注解表明 bean 的属性必须在配置的时候设置,通过一个 bean 定义的显式的 属性值或通过自动装配,若@Required 注解的 bean 属性未被设置,容器将抛出 BeanInitializ ...
- 什么是 REST / RESTful 以及它的用途是什么?
Representational State Transfer(REST)/ RESTful Web 服务是一种帮助计 算机系统通过 Internet 进行通信的架构风格.这使得微服务更容易理解和实现 ...
- python 基础数据类型汇总
数据类型小结(各数据类型常用操作) 一.数字/整型int int()强行转化数字 二.bool类型False&True bool()强行转化布尔类型. 0,None,及各个空的字符类型为Fal ...
- Pandas基础笔记
Basic knowledge of Pandas pandas库是以numpy库为基础建成的,是python数据分析的核心库.也正因如此,pandas内的数据结构与numpy的数组有许多相似的地方. ...
- 12 Factor App
The Twelve-Factor App Introduction In the modern era, software is commonly delivered as a service: c ...
- PC端免费高效的同声翻译
疫情期间上网课,对于英语听力较差或者需要观看英文视频,但实际上并没有双语字幕的这种情况下需要找一个实时的翻译工具.虽然说手机上此类软件比较多,但电脑上没有特别合适的应用可以做为一个免费实时翻译.哪怕是 ...
- 快速安装 kafka 集群
前言 最近因为工作原因,需要安装一个 kafka 集群,目前网络上有很多相关的教程,按着步骤来也能完成安装,只是这些教程都显得略微繁琐.因此,我写了这篇文章帮助大家快速完成 kafka 集群安装. ...