许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  Spring Boot整合Fluent Mybatis:配置与使用教程

Spring Boot整合Fluent Mybatis:配置与使用教程

阅读数 2
点赞 0
article_banner

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=UTCspring.datasource.username=rootspring.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@NoArgsConstructorpublic 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文件删掉就可以了


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空