Java EE notebook
  • Introduction
  • /web-customer-tracker
  • Web Service
  • AOP
  • Web Server2(Spring REST)
  • Security
  • Json
  • Web Server VS Application Server VS Web Containers
  • different between Servlet & JSP2
  • DI
  • 0
  • 1annotation inversion of control, bean scope
  • 2 annotation dependency injection
  • 3 annotation bean scope, java code config
  • 4 Spring MVC
  • rest web services
  • Spring-Hibernate0
  • Spring-Hibernate1
  • @ManyToMany
  • spring mvc work flow
  • Spring Security
  • JWT
  • @Autowired
  • Jersey REST Service
  • Spring Bean
Powered by GitBook
On this page
  • 1. @RequestParam VS @PathVariable
  • 2.@RequestMapping vs @GetMapping vs @PostMapping...

Was this helpful?

rest web services

Previous4 Spring MVCNextSpring-Hibernate0

Last updated 5 years ago

Was this helpful?

1. @RequestParam VS @PathVariable

Even though both @RequestParam and @ParthVariable is used to extract values from the HTTP request, there is a subtle difference between them.

  1. The @RequestParam is used to extract query parameters while @PathVariable is used to extract data right from the URI.

  2. @RequestParam is more useful on a traditional web application where data is mostly passed in the query abatements while @PathVariable is more suitable for RESTful web services where URL contains values e.g. , here data, which is ISBN number is part of URI.

  3. @RequestParam annotation can specify default values if a query parameter is not present or empty by using a defaultValue attribute, provided the required attribute is false.

  4. Spring MVC allows you to use multiple @PathVariable annotations in the same method, provided, no more than one argument has the same pattern.

2.@RequestMapping vs @GetMapping vs @PostMapping...

@RequestMapping(value="/orders", method = RequestMethod.GET)
public String getOrders(){
    return "All orders";
}
//equals
@GetMapping("/orders")
https://www.baeldung.com/spring-request-param
http://localhost:8080/book/9783827319333