Wednesday, February 14, 2018

How to make @requestparam optional in spring

Question:

Make spring endpoint with optional request parameters

Solution:

To make the request parameter optional on the spring controller, user JAVA 8 feature Option type or set required attribute to false.

public void count(@RequestParam(name="name") Optional name){
if (name.isPresent()) { 
 String name= name.get()
....
}
}


0 comments:

Post a Comment