springboot 整合fluent mybatis的過程,看這篇夠了
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.配置數(shù)據(jù)庫連接
spring.datasource.url= jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=root
3.創(chuàng)建數(shù)據(jù)庫表
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.創(chuàng)建Student實體類,
①實體類添加 @FluentMybatis
②實現(xiàn) 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); }
數(shù)據(jù)庫已插入
************************************
如果出現(xiàn)Mapper文件找不到路徑的異常,很可能是在之前idea中將target文件隱藏了,只需
File --> setting --> File Types 將忽視的target文件刪掉就可以了
到此這篇關于springboot 整合fluent mybatis的過程,看這篇夠了的文章就介紹到這了,更多相關springboot 整合fluent mybatis內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Activiti explorer.war示例工程使用過程圖解
這篇文章主要介紹了Activiti explorer.war示例工程使用過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-03-03MyBatis存儲過程、MyBatis分頁、MyBatis一對多增刪改查操作
本文通過一段代碼給大家介紹了MyBatis存儲過程、MyBatis分頁、MyBatis一對多增刪改查操作,非常不錯,具有參考借鑒價值,感興趣的朋友一起看看吧2016-11-11spring的xml文件打開沒有namespace等操作選項的解決方案
這篇文章主要介紹了spring的xml文件打開沒有namespace等操作選項的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09SpringBoot請求處理之常用參數(shù)注解介紹與源碼分析
SpringBoot是一種整合Spring技術棧的方式(或者說是框架),同時也是簡化Spring的一種快速開發(fā)的腳手架,本篇讓我們一起學習請求處理、常用注解和方法參數(shù)的小技巧2022-10-10