Mapping In Spring

 


Mapping in Spring

Mapping in Spring connects specific URLs to methods in your code, so when a user visits a particular URL, Spring knows which code to run. It’s like assigning an address to each function, making it easier to organize how users interact with different parts of your application.

Key Mapping Annotations

  1. @RequestMapping: This is a general-purpose mapping annotation that links URLs to methods.

    • Example: @RequestMapping("/home") links the URL /home to the associated method.
    • It can be applied to classes (class-level mapping) or methods (method-level mapping).
  2. @GetMapping and @PostMapping:

    • @GetMapping is used for GET requests, typically for reading or viewing data.
    • @PostMapping is for POST requests, usually for sending or submitting data (like a form).
    • These are specialized forms of @RequestMapping for common request types.

Comments