web In frame , There are many exceptions to deal with , Such as business exceptions , Insufficient authority, etc . Generally used try...catch Carry out exception capture processing , But in the actual project, the business module is captured abnormally , Can cause code duplication and complexity .

terms of settlement :

Set up a global exception to handle all exceptions of the framework uniformly . In the possible method of exception throw Throw to custom exception controller , Then the global exception processor processes the exception uniformly . such , The method in the controller can be simplified .


Global exception handler : use @ControllerAdvice annotation
package com.association.framework.web.exception; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import
org.springframework.web.bind.annotation.ExceptionHandler; import
org.springframework.web.bind.annotation.RestControllerAdvice; import
com.ruoyi.common.core.domain.AjaxResult; import
com.ruoyi.common.exception.LoginException; /** * Global exception handler * */
@RestControllerAdvice public class GlobalExceptionHandler { private static
final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); /** *
Login exception */ @ExceptionHandler(LoginException.class) public AjaxResult
loginException(LoginException e) { log.error(e.getMessage(), e); return
AjaxResult.error(e.getMessage()); } }

©2019-2020 Toolsou All rights reserved,
JS How to operate java Realize the function of grabbing red packets C Language programming to find a student's grade The United Nations 《 Glory of Kings 》 Please go to the studio : To save the earth Dialogue between apple and Nissan suspended ,Apple Car How's it going ?CSS architecture design China's longest high speed rail officially opened ! The fastest way to finish the race 30.5 hour First knowledge MySQL Comprehensive review ( dried food )2021 year 1 Monthly programmer salary statistics , average 14915 element How to use it quickly html and css Write static page