Spring Framework 4.3 New Feature RequestMapping: @GetMapping, @PostMapping, @PutMapping, @DeleteMapping

Spring Framework 4.3 has some Web improvements. In the article, JavaSampleApproach will introduce you about New Feature RequestMapping: @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, and @PatchMapping.

Related Posts:
Spring MVC – @RequestMapping with Methods, Headers, Params, @PathVariable and @RequestParam
Kotlin Spring MVC RequestMapping RESTful APIs with @GetMapping, @PostMapping, @PutMapping, @DeleteMapping | SpringBoot Example


I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.4.3.RELEASE

II. Overview
1. Project Structure

spring new feature request mapping project structure

2. Step to do

– Create SpringBoot project
– Create a simple model
– Create New Feature RequestMapping
– Run and check result

III. Practices
1. Create SpringBoot project

Open SpringToolSuite, on main menu, choose File->New->Spring Boot Starter, input project information. Press Next, then Finish, a SpringBoot project is created succesfully.
Open pom.xml file, add Web dependency:

2. Create a simple model

3. Create New Feature RequestMapping

Create @GetMapping, @PostMapping, @PutMapping, @DeleteMapping

4. Run and check result

Build & Run SpringBoot project then check result:

– Get RequestMapping:
new feature requestmapping spring mvc @getmapping

– POST RequestMapping:
new feature requestmapping springmvc @postmapping

– PUT RequestMapping:
new feature requestmapping springmvc @putmapping

– DELETE RequestMapping:
new feature requestmapping springmvc @deletemapping

ResfulWebServices Logs:

IV. Sourcecode

SpringMVCNewFeatureRequestMapping

By JavaSampleApproach | January 9, 2017.

Last updated on October 31, 2017.


Related Posts


4 thoughts on “Spring Framework 4.3 New Feature RequestMapping: @GetMapping, @PostMapping, @PutMapping, @DeleteMapping”

  1. is package scanning configuration required to tell Spring which Java source packages to initialize the beans from?

    1. Hi,

      With SpringBoot application, we have:
      @SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan.

      @EnableAutoConfiguration annotation implicitly defines a base search package is the root package: com.javasampleapproach.newfeaturerequestmapping.

      Regards,

  2. A little confused here. In your code you defined:

    @RequestParam("custId") is my confusion because in your demo example you’re fetching the id param via /get?id=1

    Shouldn’t that be /get?custId=1
    ???

    Great tut overall.
    Thanks!

    1. Hi Emko,

      We should change code as:

      1. For request: /get?id=1

      2. Or use: /get?custId=1 with the mapping:

      Thanks for your notice

      Regards,
      JSA

Got Something To Say:

Your email address will not be published. Required fields are marked *

*