开发者

How to get Errors(validation) in SpringFramework?

I wrote a class to implement the开发者_StackOverflow社区 interface "Validator",and now how can I get the errors message without web environment?Thanks


I think you're talking about resolving error codes to messages from the reference guide.


@Ryan Stewart's reply gives a more practical solution, but the following approach might be useful as a fallback ... or for unit testing a validator class.


The validate method is called with an object that implements the Errors interface as a parameter. On return, this object is populated with any errors that were detected by the validator. You need to extract the information you need and render it. How you do that depends on your requirements, and on how the errors object has been implemented.

If you use a errors object that has AbstractErrors as an ancestor class, the toString() method should render the error information as a message. Try that first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜