Show Topics
Hide Topics

 @DefaultValue Annotation Example

 

Sometimes URL doesn’t contain the values which are expected the methods. In that situation we can use @DefaultValue for passing default values to method parameters. @DefaultValue is good for optional parameter.

 

1.Create Dynamic web project in eclipse, convert that into Maven Project

 

 

2.Add Jersey jar files manually / through Maven by writing repo details in pom.xml

 

 

3.Create RESTFul webservice

 

 

4.Configure web.xml

 

 

5.Test Webservice directly by using URL / writing webservice client

http://localhost:8080/JAXRS-DefaultValue-Example/rest/students?rollno=1218

in Above URL we are not passing Name, Address paramaeter values. So it will take Default values passed in @DefaultValue("XXXX") annotation

 

Download Example Code