springboot 整合fluent mybatis的过程,看这篇够了
作者:Dalon_G 时间:2022-09-14 01:16:53
1.导入pom依赖
<!-- mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<!--mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.5.0</version>
</dependency>
<!-- 引入fluent-mybatis 运行依赖包, scope为compile -->
<dependency>
<groupId>com.github.atool</groupId>
<artifactId>fluent-mybatis</artifactId>
<version>1.6.8</version>
</dependency>
<!-- 引入fluent-mybatis-processor, scope设置为provider 编译需要,运行时不需要 -->
<dependency>
<groupId>com.github.atool</groupId>
<artifactId>fluent-mybatis-processor</artifactId>
<version>1.6.8</version>
</dependency>
2.配置数据库连接
spring.datasource.url= jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
3.创建数据库表
CREATE TABLE `student` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='学生表';
4.创建Student实体类,
①实体类添加 @FluentMybatis
②实现 IEntity 接口
@FluentMybatis
@Data
@NoArgsConstructor
public class Student implements IEntity {
private Long id;
private String name;
private Integer age;
}
5.重新构建项目
构建完成后,target目录下就会新建几个文件夹
6. 测试
@Autowired
private StudentMapper studentMapper; // target目录下
@RequestMapping("insert")
public void insert(){
Student student = new Student();
student.setName("dl");
student.setAge(25);
studentMapper.insert(student);
}
数据库已插入
************************************
如果出现Mapper文件找不到路径的异常,很可能是在之前idea中将target文件隐藏了,只需
File --> setting --> File Types 将忽视的target文件删掉就可以了
来源:https://blog.csdn.net/Dalon_G/article/details/119252922
标签:springboot,fluent,mybatis
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java实现文件夹解压和压缩
2022-06-07 03:00:39
浅析Mybatis 在CS程序中的应用
2023-06-24 08:44:15
![](https://img.aspxhome.com/file/2023/2/57422_0s.jpg)
java实现酒店管理系统
2023-06-09 23:59:50
C#用户定义类型转换详解
2022-06-07 11:44:32
教你怎么用Java数组和链表实现栈
2023-10-29 08:13:57
![](https://img.aspxhome.com/file/2023/0/58720_0s.png)
Java实现简单的飞机大战游戏(控制主飞机篇)
2023-11-14 13:52:56
Android Build类的详解及简单实例
2023-07-02 21:12:45
一篇文章带你初步认识Maven
2023-08-31 01:56:14
![](https://img.aspxhome.com/file/2023/7/68007_0s.png)
java比较器Comparable接口与Comaprator接口的深入分析
2022-01-20 11:51:09
Java调用groovy实现原理代码实例
2023-05-16 16:41:51
![](https://img.aspxhome.com/file/2023/3/68543_0s.jpg)
Swift洗牌动画效果的实现方法
2023-06-21 14:01:56
使用Feign传递请求头信息(Finchley版本)
2023-06-07 22:38:07
![](https://img.aspxhome.com/file/2023/2/62742_0s.jpg)
Java如何在临界区中避免竞态条件
2022-11-02 09:39:29
mybatis原理概述入门教程
2023-10-08 13:10:57
如何用Java注解和反射实现依赖注入
2022-11-04 11:34:10
Spring和SpringBoot之间的区别
2022-09-28 11:47:38
解决Springboot2.1.x配置Activiti7单独数据源问题
2022-07-28 02:24:04
spring mvc中@PathVariable / 带斜杠方式获取
2022-09-15 04:47:27
MTK Android平台开发流程
2023-06-23 08:59:11
java并发编程专题(六)----浅析(JUC)Semaphore
2023-07-27 23:30:28