Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| web:framework:spring:exceptions [2024/11/29 09:31] – créée jcheron | web: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' | + | |
| + | L' | ||
| + | |||
| + | ===== ExceptionHandler ===== | ||
| + | |||
| + | L' | ||
| + | |||
| + | <sxh java> | ||
| + | @ControllerAdvice | ||
| + | public class MainAdvice { | ||
| + | |||
| + | @ExceptionHandler({TodoNotFoundException.class, | ||
| + | public String handleTodoNotFoundException(RedirectAttributes attributes) { | ||
| + | InfoMessage msg = InfoMessage.error(" | ||
| + | attributes.addFlashAttribute(" | ||
| + | return " | ||
| + | } | ||
| + | ... | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== Validation ===== | ||
| + | |||
| + | <sxh xml> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||