springboot 整合fluent mybatis的过程,看这篇够了
程序员文章站
2022-06-24 21:05:42
1.导入pom依赖 org.mybati...
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文件删掉就可以了
到此这篇关于springboot 整合fluent mybatis的过程,看这篇够了的文章就介绍到这了,更多相关springboot 整合fluent mybatis内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!