springboot整合fluentmybatis的过程,看这篇够了1.导⼊pom依赖
<!--        mybatis-->
<dependency>
<groupId&batis.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.apachemons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.5.0</version>
</dependency>
<!-- 引⼊fluent-mybatis 运⾏依赖包, scope为compile -->
<dependency>springframework和springboot
<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⽂件删掉就可以了
到此这篇关于springboot 整合fluent mybatis的过程,看这篇够了的⽂章就介绍到这了,更多相关springboot 整合fluent mybatis内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。