springboot 整合fluent mybatis的过程,看这篇够了

网友投稿 782 2022-12-21

springboot 整合fluent mybatis的过程,看这篇够了

springboot 整合fluent mybatis的过程,看这篇够了

1.导入pom依赖

org.mybatis.spring.boot

mybatis-spring-boot-starter

1.3.1

mysql

mysql-connector-java

org.apache.commons

commons-dbcp2

2.5.0

com.github.atool

fluent-mybatis&lhttp://t;/artifactId>

1.6.8

com.github.atool

fluent-mybatis-processor

1.6.8

&ltgqIjsbKI;/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文件隐藏gqIJsbKI了,只需

File --> setting -->  File Types   将忽视的target文件删掉就可以了

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:应用软件app开发(软件开发APP)
下一篇:flutter怎么样(flutter 优点)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~