简体   繁体   English

带有@NotEmpty批注的Spring MVC表单变量,一个具有多个表单的POJO

[英]Spring MVC form valiadtion with @NotEmpty annotation, one POJO with Multiple forms

I am working on spring mvc with annotations. 我正在使用带有注释的spring mvc。

I have a POJO with three fields userName, password and mailId which are annotated as @NotEmpty . 我有一个POJO,其中包含三个字段userName,password和mailId ,它们被注释为@NotEmpty I have two forms : 我有两种形式:

  1. Loginform.jsp : contains two input fields userName and password. Loginform.jsp :包含两个输入字段userName和password。
  2. Forgotpassword.jsp : contains only one input field mailId. Forgotpassword.jsp :仅包含一个输入字段mailId。

The problem is if I use the same pojo for both jsp forms it's giving me binding result errors, as for login.jsp I don't need mailId, and for forgotpassword.jsp I don't need userName and password, but all these fields are annotated as @NotEmpty in my POJO,so gives validation error. 问题是,如果我对两种jsp形式使用相同的pojo,则会给我带来绑定结果错误,至于login.jsp,我不需要mailId,forgotpassword.jsp,我不需要userName和密码,但是所有这些字段在我的POJO中被标注为@NotEmpty ,因此给出了验证错误。

Q: How to deal with the situation? 问:如何处理情况? Do I need to create separate POJO for each Form? 我需要为每个表单创建单独的POJO吗?

According to me, login and forgot-password are two very different business usecases, and as such deserve separate POJOs. 根据我的说法,登录名和忘记密码是两个非常不同的业务用例,因此应使用单独的POJO。 Doing so would also, in future, guard you against accidently exposing the password in forgot-password page. 这样做还可以防止日后在忘记密码页面中意外泄露密码。

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

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