验证生成的JAXB类(JSR 303 / Spring) [英] Validation for generated JAXB Classes (JSR 303 / Spring)

查看:87
本文介绍了验证生成的JAXB类(JSR 303 / Spring)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JAXB(maven-jaxb2-plugin)从模式生成域对象(请求和响应)

我想为几个属性添加验证(notnull / empty)。我想有自定义Bean验证,应用程序是一个REST服务,我使用的是Spring 3和JSR 303
但我不认为我可以使用JSR 303验证对象,因为它是从模式生成的。

I Generated domain objects from schema (request & response) using JAXB (maven-jaxb2-plugin)
I would like add validations (notnull /empty) for couple of attributes. I would like to have custom Bean Validation, the application is a REST service, i'm using Spring 3 and JSR 303 but i dont think i can use JSR 303 to validate the object as it is generated from the schema.

有人可以给我一个关于如何完成这项工作的正确方向。

can someone give me a nudge in the right direction on how to get this done.

推荐答案

我们一直在使用 Krasa JAXB插件来生成JSR来自XSD文件的303注释模型bean,然后告诉Spring 自动验证输入bean。如果你有很好的XSD,这会产生非常漂亮,非常简洁,非常干的代码。

We've been using the Krasa JAXB plugin to generate JSR 303-annotated model beans from XSD files, and then telling Spring to automatically validate the input beans. This results in very nice, very terse, very DRY code if you have good XSDs.

这篇关于验证生成的JAXB类(JSR 303 / Spring)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆