티스토리 뷰

Skill/JPA

[JPA] DB에 없는 필드 관련

진열사랑 2020. 8. 14. 09:56

사용자 정보 저장할 때 비밀번호와, 비밀번호확인이 있다...

비밀번호 확인은 Front단에서만 점검용으로 사용한다.. 하지만 화면에 <input>으로 존재하므로  

JSON.stringify($("#facilityForm").serializeObject())를 하다 보면 자연스레 DB에 없는 column들도 넘어가게 마련..

이럴 때 Back(Server or Api)단에서 DB에 없는 필드를 무시하는 조치가 필요하다...

1. @Transient 추가

import javax.persistence.Transient;

@Transient는 JPA관련 annotation이다.

 

그런데 두두.. 이것으로만으로 해결되지 않는 문제가 발생했다.

 

Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized field "userPwd2"

(com.mindone.okch.common.domain.User) , not marked as ignorable; nested exception is

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: 

(15 known properties: "regDt", "userAra", "userId", "phone", "regId", "modDt", "ugrpCde", "userAtt", "userGrp", "useYn", "modId", "userNam", "userPwd", "email", "attCode"])

 

2. @JsonIgnoreProperties(ignoreUnknown = true)

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties는 jackson관련 annotation이다.

 

위 문장 추가시 해결!

 

@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
//@Getter @Setter
@Table(name = "CM_USR")
public class User extends AbstractTbl { // 사용자
	
	@Id
	@ApiModelProperty(value = "사용자아이디")
	@Column(name = "USER_ID")
	private String userId;
	
	@ApiModelProperty(value = "비밀번호")
	@Column(name = "USER_PWD")
	private String userPwd;
	
	@ApiModelProperty(value = "비밀번호확인")
	@Transient
	private String userPwd2;
}

 

참고 : https://medium.com/@circlee7/jackson-annotations-19886933a252

 

Jackson annotations

json관련 jackson 에서 지원하는 유용한 어노테이션 기능들을 살펴보자

medium.com

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함