当前位置:网站首页>11、 Exception handler
11、 Exception handler
2022-07-26 04:28:00 【Time postman】
1、 Configuration based exception handling
SpringMVC It provides an interface to handle exceptions during the execution of controller methods :HandlerExceptionResolver
HandlerExceptionResolver The implementation classes of the interface are :DefaultHandlerExceptionResolver and SimpleMappingExceptionResolver
SpringMVC Provides a custom exception handler SimpleMappingExceptionResolver, Usage mode :
<!-- Exception handler -->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<!--
prop The key of represents an exception that occurs during the execution of the processor method
prop The value of indicates that if a specified exception occurs , Set a new view name , Jump to the specified page
-->
<prop key="java.lang.ArithmeticException">error</prop>
</props>
</property>
<!--
exceptionAttribute: Set a property name , Share the exception information in the request domain
-->
<property name="exceptionAttribute" value="ex"></property>
</bean>
2、 Annotation based exception handling
//@ControllerAdvice Identify the current class as the exception handling component
@ControllerAdvice
public class ExceptionController {
//@ExceptionHandler Used to set the exception handled by the identified method
@ExceptionHandler(ArithmeticException.class)
//ex Represents the exception object in the current request processing
public String handleArithmeticException(Exception ex, Model model){
model.addAttribute("ex", ex);
return "error";
}
}
边栏推荐
- 香甜的黄油
- What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
- 生活相关——十年的职业历程(转)
- Can literature | relationship research draw causal conclusions
- HelloWorld case analysis
- I.MX6U-ALPHA开发板(GPIO中断实验)
- MySQL log classification: error log, binary log, query log, slow query log
- Optimization analysis and efficiency execution of MySQL
- Page pull-up refresh and pull-down loading
- Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
猜你喜欢

TIA botu WinCC Pro controls the display and hiding of layers through scripts

Acwing_ 12. Find a specific solution for the knapsack problem_ dp

Apisex's exploration in the field of API and microservices

Sangi diagram of machine learning (for user behavior analysis)

机器学习之信用卡欺诈检测

Can literature | relationship research draw causal conclusions

MySQL - multi table query - Cartesian product sum, correct multi table query, equivalent connection and unequal connection, inner connection and outer connection

egg-ts-sequelize-CLI

Creative design principle of youth maker Education

VM virtual machine has no un bridged host network adapter, unable to restore the default configuration
随机推荐
远坂凛壁纸
How to download the supplementary literature?
MATLAB绘图
UE4 获取玩家控制权的两种方式
How to transfer English documents to Chinese?
Use Baidu PaddlePaddle easydl to complete garbage classification
Keil v5安装和使用
旋转数组最小数字
吴恩达机器学习课后习题——线性回归
1. Mx6u-alpha development board (main frequency and clock configuration experiment)
【UOJ 429】串串划分(Runs)(容斥)+ 有关 Lyndon Tree 及其应用的小小记录
Rotate array minimum number
华为再发“天才少年”全球召集令,有人曾放弃360万年薪加入
Compiled by egg serialize JS
再获认可 | 赛宁网安连续上榜《CCSIP 2022中国网络安全产业全景图》
Firewall command simple operation
一、基础入门
数组排序3
Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
qt编译报错整理及Remote模块下载