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()
....
}
}


Related Posts:

  • 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 voi… Read More
  • Spring REST web service Test We can test the Spring REST web service by following : 1. By java Junit class. 2. By SoapUI. 3. By Firefox browser plugin REST CLIENT. 4. By Chrome browser plugin POST MAN. 1. By java Junit class : We can write the j… Read More
  • Spring + JPA + Hibernate Sample IntroductionStand-alone Spring application sample, Spring framework supports the persistence layer to be fully implemented through JPA. Simple example of configure the Spring needed components to perform persistence over sta… Read More

0 comments:

Post a Comment