Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference b/w @RequestParam and @QueryParam Anotation

Tags:

spring-mvc

What is main difference between @RequestParam and @QueryParam in Spring MVC controller?

like image 591
user2875922 Avatar asked Nov 03 '14 07:11

user2875922


People also ask

What's the difference between @PathParam and @QueryParam RESTful annotations?

PathParam could be used to drill down to entity class hierarchy. Whereas, QueryParam could be reserved for specifying attributes to locate the instance of a class.

What does the @RequestParam annotation do?

@RequestParam annotation enables spring to extract input data that may be passed as a query, form data, or any arbitrary custom data.

What is the difference between @RequestParam and @PathVariable annotation?

The @PathVariable annotation is used for data passed in the URI (e.g. RESTful web services) while @RequestParam is used to extract the data found in query parameters.

What is the @QueryParam annotation?

The @QueryParam annotation allows you to map a URI query string parameter or url form encoded parameter to your method invocation.


2 Answers

@QueryParam is a JAX-RS framework annotation and @RequestParam is from Spring.

like image 192
Sergii Getman Avatar answered Sep 23 '22 05:09

Sergii Getman


Apart from these mentioned differences in framework, one major difference is @RequestParam will always expect a value to bind. Hence, if value is not passed, it will give error. This is not the case in @QueryParam

To explicitly give the option, use required = false while using @RequestParam

like image 22
Divya Avatar answered Sep 23 '22 05:09

Divya