您的位置:首页 > 编程语言 > Java开发

spring异常

2015-12-26 22:48 441 查看
*** SpringMVC自定义异常对应的status code

Exception HTTP Status Code

ConversionNotSupportedException 500 (Internal Server Error)

HttpMediaTypeNotAcceptableException 406 (Not Acceptable)

HttpMediaTypeNotSupportedException 415 (Unsupported Media Type)

HttpMessageNotReadableException 400 (Bad Request)

HttpMessageNotWritableException 500 (Internal Server Error)

HttpRequestMethodNotSupportedException 405 (Method Not Allowed)

MissingServletRequestParameterException 400 (Bad Request)

NoSuchRequestHandlingMethodException 404 (Not Found)

TypeMismatchException 400 (Bad Request)

<property name="exceptionMappings">
<props>
<!-- 这里你可以根据需要定义N多个错误异常转发 -->
<prop key="java.sql.SQLException">dbError</prop> <!-- 数据库错误(dbError.jsp) -->
<prop key="org.springframework.web.bind.ServletRequestBindingException">bizError</prop> <!-- 参数绑定错误(如:必须参数没传递)(bizError.jsp) -->
<prop key="java.lang.IllegalArgumentException">bizError</prop>  <!-- 参数错误(bizError.jsp) -->
<prop key="org.springframework.validation.BindException">bizError</prop>  <!-- 参数类型有误(bizError.jsp) -->
<prop key="java.lang.Exception">unknowError</prop>  <!-- 其他错误为'未定义错误'(unknowError.jsp)  -->
</props>
</property>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: