• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

springboot 搞代码 4年前 (2022-01-05) 54次浏览 已收录 0个评论

这篇文章主要介绍了springboot 整合fluent mybatis的过程,配置数据库连接创建数据库的详细代码,本文给大家介绍的非常详细,需要的朋友可以参考下

1.导入pom依赖

 <!--        mybatis--> org.mybatis.spring.bootmybatis-spring-boot-starter1.3.1<!--mysql依赖--> mysqlmysql-connector-java org.apache.commonscommons-dbcp22.5.0<!-- 引入fluent-mybatis 运行依赖包, scope为compile --> com.github.atoolfluent-mybatis1.6.8<!-- 引入fluent-mybatis-processor, scope设置为provider 编译需要,运行时不需要 --> com.github.atoolfluent-mybatis-processor1.6.8

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, <strong style="color:transparent">来源gaodai#ma#com搞@@代~&码*网</strong>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的过程,看这篇够了的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:springboot 整合fluent mybatis的过程,看这篇够了

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址