springboot對jpa簡單操作CRUD

2021-10-25 08:10:22 字數 1137 閱讀 3050

org.springframework.boot

spring-boot-starter-data-jpa

spring:

datasource:

url: jdbc:mysql://localhost:3306/mytest

type: com.alibaba.druid.pool.druiddatasource

username: root

password: root

driver-class-name: com.mysql.jdbc.driver //驅動

jpa:

hibernate:

ddl-auto: update //自動更新

show-sql: true //日誌中顯示sql語句

jpa.hibernate.ddl-auto是hibernate的配置屬性,其主要作用是:自動建立、更新、驗證資料庫表結構。該引數的幾種配置如下:

·create-drop:每次載入hibernate時根據model類生成表,但是sessionfactory一關閉,表就自動刪除。

·update:最常用的屬性,第一次載入hibernate時根據model類會自動建立起錶的結構(前提是先建立好資料庫),以後載入hibernate時根據model類自動更新表結構,即使表結構改變了但表中的行仍然存在不會刪除以前的行。要注意的是當部署到伺服器後,表結構是不會被馬上建立起來的,是要等應用第一次執行起來後才會。

·validate:每次載入hibernate時,驗證建立資料庫表結構,只會和資料庫中的表進行比較,不會建立新錶,但是會插入新值。

@entity

@data

@table(name="mytest")

public class person

@log("查詢測試生產3")

@apioperation("查詢測試生產3")

@preauthorize("@el.check('mytest2:list')")

public responseentityquery(mytest2querycriteria criteria, pageable pageable)

學習日誌 springboot整合JPA

1.編寫實體類 entity 告訴spring這是乙個實體類 table 之地你和哪個表對映。不寫則預設是user,即實體類名的小寫。指定 name public class user 3.配置檔案編寫 spring datasource driver class name com.mysql.jd...

Springboot 之 使用JPA進行分頁操作

test public void test1 注意 繼承了jparepository後的iuserservice擁有了findall的過載方法,當傳入引數為pageable時,返回傳則是乙個分頁的物件page。在建立pageable介面的例項時需要指定其子類pagerequest,在pagerequ...

spring boot 資料訪問3 JPA

1 匯入包 org.springframework.boot spring boot starter data jpa spring datasource username root password 123456 url jdbc mysql driver class name com.mysql...