Skip to main content

Posts

Showing posts with the label Spring requestmapping

Spring 4.3 - New @RequestMapping annotation

Spring 4.3 - @GetMapping, @PostMapping, @PutMapping and @DeleteMapping There are some new improvements in Spring Boot 1.4 and Spring 4.3 which lead to a better readability and some use of annotations, particularly with HTTP request methods. We usually map GET, PUT, POST and DELETE HTTP method in rest controller in the following way. @RestController @RequestMapping ( "/api/employees" ) public class EmployeeController { @RequestMapping public ResponseEntity < List < Employee >> getAll () { return ResponseEntity . ok ( Collections . emptyList ()); } @RequestMapping ( "/{employeeId}" ) public ResponseEntity < Employee > findById ( @PathVariable Long employeeId ) { return ResponseEntity . ok ( EmployeeStub . findById ( employeeId )); } @RequestMapping ( method = RequestMethod . POST ) public ResponseEntity < Employee > addEmployee ( @RequestBody Employee employee ) { return Respons