본문 바로가기

개발중/Spring

@RequestParam Null 잡기

728x90
반응형

 

 

 

 


String 형 null 값 허용하기

첫번째 방법

@RequestParam 안에 required = false

 

@RequestParam(value="binsoo", required = false) String bonsoo

 

 

두번째 방법

 @Nullable null 이어도 받겠다.

 

@ApiParam( 
value    = "binsoo", 
name     = "binsoo", 
type     = "String" )  
@RequestParam @Nullable String binsoo)
 

int 형 null 값 허용하기

String Type 은 잘 잡히는데 int 형이 잘 잡히지 않는다.

기본값 설정 후 int 형이 null 일 경우에 기본값으로 세팅이 된다.(defaultValue="0") 

 

@ApiParam( 
value    = "binsoo", 
name     = "binsoo", 
type     = "int" )  
@RequestParam (defaultValue="0") int binsoo)
 

 

 

 

 

 

728x90
반응형