



下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第SpringBoot:JPA+AuditingEntityListener時區(qū)設(shè)置方式目錄JPA+AuditingEntityListener時區(qū)設(shè)置可在應(yīng)用配置中添加如下配置@EntityListeners(AuditingEntityListener.class)介紹@EntityListenersAuditingEntityListener.class
JPA+AuditingEntityListener時區(qū)設(shè)置
在SpringBoot項目中,如果應(yīng)用啟用了EnableJpaAuditing并且使用AuditingEntityListener對實體的創(chuàng)建時間、更新時間進(jìn)行自動審計,可能存在生成時間的時區(qū)和系統(tǒng)時區(qū)不一致的問題。
可在應(yīng)用配置中添加如下配置
將時區(qū)設(shè)定為指定時區(qū):
perties.hibernate.jdbc.time_zone=GMT+8
@EntityListeners(AuditingEntityListener.class)介紹
@EntityListeners
源碼
*Specifiesthecallbacklistenerclassestobeusedforan
*entityormappedsuperclass.Thisannotationmaybeapplied
*toanentityclassormappedsuperclass.
*@sinceJavaPersistence1.0
@Target({TYPE})
@Retention(RUNTIME)
public@interfaceEntityListeners{
/**Thecallbacklistenerclasses*/
Class[]value();
分析
從源碼的注釋中可以很清楚的了解到該注解的作用,簡單翻譯如下:該注解用于指定Entity或者superclass上的回調(diào)監(jiān)聽類。該注解可以用于Entity或者superclass上。
AuditingEntityListener.class
源碼
*JPAentitylistenertocaptureauditinginformationonpersitingandupdatingentities.Togetthisoneflyingbe
*sureyouconfigureitasentitylistenerinyour{@codeorm.xml}asfollows:
*pre
*persistence-unit-metadata
*persistence-unit-defaults
*entity-listeners
*entity-listener/
*/entity-listeners
*/persistence-unit-defaults
*/persistence-unit-metadata
*/pre
*Afterthatit'sjustamatterofactivatingauditinginyourSpringconfig:
*pre
*#064;Configuration
*#064;EnableJpaAuditing
*classApplicationConfig{
*/pre
*pre
*jpa:auditingauditor-aware-ref="yourAuditorAwarebean"/
*/pre
*@authorOliverGierke
*@authorThomasDarimont
@Configurable
publicclassAuditingEntityListener{
privateObjectFactoryAuditingHandlerhandler;
*Configuresthe{@linkAuditingHandler}tobeusedtosetthecurrentauditoronthedomaintypestouched.
*@paramauditingHandlermustnotbe{@literalnull}.
publicvoidsetAuditingHandler(ObjectFactoryAuditingHandlerauditingHandler){
Assert.notNull(auditingHandler,"AuditingHandlermustnotbenull!");
this.handler=auditingHandler;
*Setsmodificationandcreationdateandauditoronthetargetobjectincaseitimplements{@linkAuditable}on
*persistevents.
*@paramtarget
@PrePersist
publicvoidtouchForCreate(Objecttarget){
if(handler!=null){
handler.getObject().markCreated(target);
*Setsmodificationandcreationdateandauditoronthetargetobjectincaseitimplements{@linkAuditable}on
*updateevents.
*@paramtarget
@PreUpdate
publicvoidtouchForUpdate(Objecttarget){
if(handler!=null){
handler.getObject(
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 行政管理用戶滿意度測試試題及答案
- 2025年執(zhí)業(yè)醫(yī)師考試溫故而知新試題及答案
- 2025年學(xué)期語文考試試題及答案大揭密
- 行政管理??莆幕荚囶}目和答案
- 護(hù)理行為規(guī)范試題及答案分享
- 2025年執(zhí)業(yè)醫(yī)師考試專家點評與試題及答案
- 2025年執(zhí)業(yè)藥師考試高頻試題及答案
- 行政法學(xué)復(fù)習(xí)過程中的高效學(xué)習(xí)法:試題及答案
- 文化認(rèn)同在社會融合中的作用試題及答案
- 加倍努力衛(wèi)生資格考試試題及答案
- 管道支吊架培訓(xùn)教材課件
- COPD病人出院計劃
- 公司文件會審表
- (中職)體育與健康第七章 籃球運動課件
- 2、工程工質(zhì)量保證體系框圖
- 地鐵工程車輛段路基填方施工方案
- 路基路面排水設(shè)計(配圖說明共50頁)
- YY∕T 0617-2021 一次性使用人體末梢血樣采集容器
- 有關(guān)種子農(nóng)藥化肥購銷合同模板
- 山東水利定額使用說明
- 鋼結(jié)構(gòu)焊接變形的火焰矯正方法
評論
0/150
提交評論