简体   繁体   English

Spring Framework表单验证,Hibernate bean和bean填充

[英]Spring Framework form validation, Hibernate beans and bean populating

How can I make beans that contain Hibernate annonations and at the same time it would contain form validation annonations? 如何使包含Hibernate注释的bean同时包含表单验证注释? And when I catch HTTP request I would like automatically populate this bean with form data. 当我捕获HTTP请求时,我想用表单数据自动填充此bean。 Is there any way to do this with Spring Framework tools? Spring Framework工具有什么办法做到这一点? And are there any tools to print bean as html to jsp page? 并且有什么工具可以将bean作为html打印到jsp页面?

How can I make beans that contain Hibernate annonations and at the same time it would contain form validation annonations? 如何使包含Hibernate注释的bean同时包含表单验证注释?

You mean hibernate annotations like @org.hibernate.annotations.Entity and bean validation annotations like @javax.validation.constraints.NotNull ? 您是说像@org.hibernate.annotations.Entity类的休眠注释,还是像@javax.validation.constraints.NotNull类的bean验证注释? If so, you should first consider use only javax.* annotations, because (among many more reasons) your code can be portable in any provider. 如果是这样,您应该首先考虑仅使用javax.*注释,因为(还有许多原因)您的代码可以在任何提供程序中移植。

And when I catch HTTP request I would like automatically populate this bean with form data. 当我捕获HTTP请求时,我想用表单数据自动填充此bean。 Is there any way to do this with Spring Framework tools? Spring Framework工具有什么办法做到这一点?

If you're talking about Spring MVC, then it should be done automatically, you just have to create your @Controller methods and insert the appropriate parameters. 如果您正在谈论Spring MVC,那么它应该自动完成,只需创建@Controller方法并插入适当的参数即可。 You should take a look at the documentation at http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html . 您应该看一下http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html上的文档。

If you're working with pure servlets, you should consider using http://commons.apache.org/beanutils/ . 如果使用纯servlet,则应考虑使用http://commons.apache.org/beanutils/

And are there any tools to print bean as html to jsp page? 并且有什么工具可以将bean作为html打印到jsp页面?

Didn't catch that either. 也没有抓住。 If you mean create a insert/edit form based on the bean's attributes, I don't know any tool or tag or thing that does the trick. 如果您要基于Bean的属性创建一个插入/编辑表单,那么我不知道有什么工具或标签或实现此目的的东西。 But there are tools to generate html code based on a class. 但是有一些工具可以基于类生成html代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM