Request Mapping

Request Mapping

  • @GetMapping

    @GetMapping("/users")
    public ResponseEntity<List<User>> getUsers() {
        List<User> users = // Fetch users
        return ResponseEntity.ok(users);
    }
    
  • @PostMapping

    @PostMapping("/users")
    public ResponseEntity<User> createUser(@RequestBody User user) {
        User createdUser = // Create user
        return ResponseEntity.status(HttpStatus.CREATED).body(createdUser);
    }
    
  • @PutMapping

    @PutMapping("/users/{id}")
    public ResponseEntity<User> updateUser(@PathVariable("id") Long id, @RequestBody User user) {
        User updatedUser = // Update user
        return ResponseEntity.ok(updatedUser);
    }
    
  • @DeleteMapping

    @DeleteMapping("/users/{id}")
    public ResponseEntity<Void> deleteUser(@PathVariable("id") Long id) {
        // Delete user
        return ResponseEntity.noContent().build();
    }