spring mvc4 笔记
生活随笔
收集整理的這篇文章主要介紹了
spring mvc4 笔记
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
處理異常
rest httpapi
HttpStatus (500,404等狀態碼)、ResponseEntity(返回實體)(T t,HttpStatus hs)
在類級別使用@ExceptionHandler
使用@ControllerAdvice,捕獲所有控制器或控制器的一個子集所拋出的全局異常
package masterSpringMvc.error;import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus;@ControllerAdvice public class EntityNotFoundMapper {@ExceptionHandler(EntityNotFoundException.class)@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Entity could not be found") public void handleNotFound() { } }處理控制器拋出的所有 EntityNotFoundException 異常
Spring HATEOAS 和 Spring Data REST
轉載于:https://my.oschina.net/haloooooo/blog/1619486
總結
以上是生活随笔為你收集整理的spring mvc4 笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JSP第四篇【EL表达式介绍、获取各类数
- 下一篇: Shiro切入Spring的方式