当前位置: 动力学知识库 > 问答 > 编程问答 >

Spring rest support - Http code 422

问题描述:

Does anyone know if there is support for returning http code 422 from Spring MVC? I am developing some strictly RESTFul services using Spring MVC and I want to do data validations for all POST requests.

The general convention that everyone is going towards is passing the validation messages back in the body but with a 422 response.

Is there some Spring bean that I can configure which automatically returns a 422 after it executes my custom validation code?

Thanks,

Gotz

网友答案:

I think you can do this with an org.springframework.web.servlet.HandlerInterceptor

It has 3 methods, preHandle is called before the request handler method is invoked, and postHandle after the request handler method retunrs and before the view is rendered, and afterComplete is invoked after the view is rendert.

I think you can use this to hook into the web request chain to modify request and response.

分享给朋友:
您可能感兴趣的文章:
随机阅读: