Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gauravrmazra
Created January 8, 2017 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauravrmazra/8b84c82a49b193efe3b6c083d6424045 to your computer and use it in GitHub Desktop.
Save gauravrmazra/8b84c82a49b193efe3b6c083d6424045 to your computer and use it in GitHub Desktop.
Pre Spring 4.3 request mapping annotatio example
@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 ResponseEntity.ok(EmployeeStub.addEmployee(employee));
}
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<Employee> updateEmployee(@RequestBody Employee employee) {
return ResponseEntity.ok(EmployeeStub.updateEmployee(employee));
}
@RequestMapping(path = "/{employeeId}", method = RequestMethod.DELETE)
public ResponseEntity<Employee> deleteEmployee(@PathVariable Long employeeId) {
return ResponseEntity.ok(EmployeeStub.deleteEmployee(employeeId));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment