Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.
@RestController
public class MonControleur {
@GetMapping("/hello")
public String sayHello() {
return "Bonjour le monde !";
}
}
@GetMapping("/search")
public List<User> searchUsers(@RequestParam String query) {
// ...
}
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(UserNotFoundException.class)
public ResponseEntity<String> handleUserNotFound(UserNotFoundException ex) {
return new ResponseEntity<>(ex.getMessage(), HttpStatus.NOT_FOUND);
}
}
@DeleteMapping("/utilisateurs/{id}")
public void deleteUser(@PathVariable Long id) {
// ...
}
@GetMapping("/utilisateurs/{id}")
public User getUserById(@PathVariable Long id) {
// ...
}
@PostMapping("/utilisateurs")
public User createUser(@RequestBody User user) {
// ...
}
@PutMapping("/utilisateurs/{id}")
public User updateUser(@PathVariable Long id, @RequestBody User user) {
// ...
}
@GetMapping("/utilisateurs/{id}")
public ResponseEntity<User> getUser(@PathVariable Long id) {
User user = service.findById(id);
return ResponseEntity.ok(user);
}
public ResponseEntity<User> createUser(@Valid @RequestBody User user) { ... }
@GetMapping("/events")
public Flux<Event> getEvents() {
return eventRepository.findAll();
}