DOMDOM
0posts
today
total
personal posts · since 2021

Fragments
of a day.

A small notebook for slow moments slipping by.

2023 IT Creator
2024 Food Creator
2025 News Creator
2026 News Creator

Latest Posts최근

tistory view

Back to Home

[springboot] DTO에 추가된 필드 중 null값인 필드는 보이지않게 하는 방법

728x90
반응형

 

 

 

만약 DTO에는 a,b,c,d,e 라는 필드가 추가되어있고

Mapper에서는 select a,b from table 쿼리로 데이터를 가져올 때,

디폴트로 c,d,e는 null값으로 추가되어 출력된다.

이때 c,d,e가 함께 출력되지 않도록 하는 간단한 방법!

 

DTO에 @JsonInclude(JsonInclude.Include.NON_NULL)를 추가해준다.!!!

 


import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class YourDTO {
	private String a; 
    private String b; 
    private String c; 
    private String d; 
    private String e;
    ...
}

 

 

 

728x90
반응형

Comments

Thanks for staying up late.

keep wandering · keep listening