Skip to main content

Command Palette

Search for a command to run...

Java : Spring boot , @RequestParam vs @PathVariable

Published
1 min read
S

I love learning about technology and sharing that with others

Motivation

This question was asked to me during an interview and i was not able to answer this question properly so i will demystify this concept.

both will help us to get the data from the request url

Example :

http://localhost:8080/shop/order/1001/receipts?date=12-05-2017,

then you can use the @RequestParam annotation to retrieve the query parameter date

@PathVariable to extract the orderId i.e. “1001” as shown below:

@RequestMapping(value="/order/{orderId}/receipts", method = RequestMethod.GET)

public List listUsersInvoices(
@PathVariable("orderId") int order,

@RequestParam(value = "date", required = false) Date dateOrNull) {
}
2 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)