天天看點

springboot——資料通路——整合mybatis

springboot沒有直接提供和mybatis對接的stater,但是mybatis自己提供了整合的。

想要在springboot中使用mybatis還是友善的。

步驟:

  • 可以在建立項目的時候就直接勾選住依賴,也可以自己增加依賴:
springboot——資料通路——整合mybatis
  • 直接把sql建表語句放在下圖的指定位置,然後配置yml檔案。就可以自動建立了。
springboot——資料通路——整合mybatis

注解版Mybatis

  • 簡單的CRUD
springboot——資料通路——整合mybatis
  • 需要主鍵自增
springboot——資料通路——整合mybatis

在注解的情況下:想要像配置一樣開啟駝峰命名法

springboot——資料通路——整合mybatis

對于每一個mapper類,我們都需要在類上添加注解@mapper,如果不想這樣做,就可以開啟包掃描。

springboot——資料通路——整合mybatis

 配制檔案版Mybatis

對Mybatis不熟悉的提供一個中文文檔:

​​http://www.mybatis.org/mybatis-3/zh/index.html​​

步驟:

  • 全局配置檔案
springboot——資料通路——整合mybatis
  • 寫mapper
springboot——資料通路——整合mybatis
  • 配置檔案:
  • 識别到相關的配置檔案:

繼續閱讀