我使用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)
发布评论