1. 程式人生 > >spring boot資料庫操作彙總

spring boot資料庫操作彙總

1 關於orm

orm即object relational mapping,物件關係對映,即將資料庫中的表對映成物件。

常用的orm有以下:

mybatis

spring jdbc template

hibernate

spring data jpa

如果在spring boot專案中用的是mybatis的話,引入依賴mybatis-spring-boot-starter;

如果在spring boot專案中用的是spring jdbc template的話,引入的依賴spring-boot-starter-jdbc;

如果在spring boot專案中用的是spring data jpa的話,引入的依賴是spring-boot-starter-data-jdbc;

如果在spring boot專案中用的是hibernate的話,引入的依賴是spring-boot-starter-data-jpa。

 

2 關於資料庫的驅動

真正的資料庫操作需要使用資料庫驅動,mysql和postgresql都有直接的驅動。

mysql的驅動依賴是mysql-connector-java;

 

orm的操作是建立在資料庫驅動的基礎之上的。