web:framework:spring:exceptions

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
web:framework:spring:exceptions [2024/11/29 09:31] – créée jcheronweb:framework:spring:exceptions [2025/08/12 02:35] (Version actuelle) – modification externe 127.0.0.1
Ligne 5: Ligne 5:
   * Dans le **ControllerAdvice** pour une gestion centralisée.   * Dans le **ControllerAdvice** pour une gestion centralisée.
  
-L'annotation ''@ExeptionHandler'' peut être associée à une ou plusieurs exeptions+ 
 +L'annotation ''@ExeptionHandler'' peut être associée à une ou plusieurs exceptions. 
 + 
 +===== ExceptionHandler ===== 
 + 
 +L'utilisation de ExceptioinHandler dans le ControllerAdvice permet de centraliser la gestion des exceptions : 
 + 
 +<sxh java> 
 +@ControllerAdvice 
 +public class MainAdvice { 
 + 
 +    @ExceptionHandler({TodoNotFoundException.class, NoSuchElementException.class}) 
 +    public String handleTodoNotFoundException(RedirectAttributes attributes) { 
 +        InfoMessage msg = InfoMessage.error("Erreur", "La tâche demandée n'existe pas"); 
 +        attributes.addFlashAttribute("msg", msg); 
 +        return "redirect:/"; 
 +    } 
 +... 
 +
 +</sxh> 
 + 
 + 
 + 
 + 
 +===== Validation ===== 
 + 
 +<sxh xml> 
 +<dependency>  
 +    <groupId>org.springframework.boot</groupId>  
 +    <artifactId>spring-boot-starter-validation</artifactId>  
 +</dependency> 
 +</sxh> 
 + 
  
  • web/framework/spring/exceptions.1732869106.txt.gz
  • Dernière modification : il y a 4 jours
  • (modification externe)