티스토리 뷰

Auditing을 이용해서 공통으로 등록일과 수정일을 가져와 사용하는 형태로 만들면서 

DB 쪽 설계가 char(14) 형태로 나왔다. 

이 부분에 대해 얘기를 하였으나 기존 시스템과의 연계 때문에 어쩔수 없다는 답변을 듣고 

auditing을 통해 받아온 localDateTime을 String 형태로 변경 해야 했다.

여러 방법을 시도 해 봤으나

@JsonFormat도 안되고

@DateTimeFormat도 안되었다.

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {
	
	@CreatedDate
	@JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyyMMddHHmmss", timezone="Asia/Seoul")
	@DateTimeFormat(pattern = "yyyyMMddHHmmss")
	@ApiModelProperty(value = "생성일시")
	private LocalDateTime crtnDtm;
	
	@LastModifiedDate
	@JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyyMMddHHmmss", timezone="Asia/Seoul")
	@DateTimeFormat(pattern = "yyyyMMddHHmmss")
	@ApiModelProperty(value = "최종변경일시")
	private LocalDateTime lstChngDtm;
	
}

 

함께 일하시는 분의 도움으로 해결을 하여서 기록으로 남긴다.

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {
	
	@ApiModelProperty(value = "생성일시")
	private String crtnDtm;
	
	@ApiModelProperty(value = "최종변경일시")
	private String lstChngDtm;

	@PrePersist
	public void onPrePersist() {
		this.crtnDtm = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
		this.lstChngDtm = this.crtnDtm;
	}
	
	@PreUpdate
	public void onPreUpdate() {
		this.lstChngDtm = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
	}
}

 

위와 같은 형태로 만들면 사용이 가능하다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함