0

私のリポジトリには、@CreatedBy@CreationTimestampと注釈が付けられているフィールドがあります。私はスプリングセキュリティを認証に使用しています。すべて正常に動作し、DB内のフィールドは正しいユーザ名creationTimestampで満たされます。しかし、時にはを自分で作成して列に設定する必要がある場合は、@CreatedBy注釈を上書きする必要があります。それを達成する方法?Spring Auditorwareが手動で作成したセット

答えて

0

ユーザーIDは、手動の方法の下に使用して設定することができます。

@PrePersist 
protected void onCreate() { 
    //retrieve userid here and set it. 
    String userUid = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 
    setCreatedBy(userUid); 
} 

@PreUpdate 
protected void onUpdate() { 
    //retrieve userid here and set it. 
    String userUid = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 
    setUpdatedBy(userUid); 
} 
+0

まあこれで問題がuserIdをが異なっていること、すべての時間です。 @PrePersistはパラメータを取りません。どのようにパラメータを渡すのですか? – JamesLinux

関連する問題