Java – spring MVC cross domain validation: code smell?

Is this a taste of code or the best way to implement cross field verification in spring forms?

@FieldrequiredIf.List({
    @FieldrequiredIf(ifField="firstHomePhoneNumber",matches={EMPTY,NULL},require ="firstMobilePhoneNumber",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.firstMobilePhoneNumber",groups=FirstLife.class),@FieldrequiredIf(ifField="secondHomePhoneNumber",require ="secondMobilePhoneNumber",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.secondMobilePhoneNumber",groups=SecondLife.class),@FieldrequiredIf(ifField="lifeAssuredIsPolicyOwner",matches={FALSE},require ="policyOwnerName",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.policyOwnerName"),require ="policyOwnerAddress",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.policyOwnerAddress"),@FieldrequiredIf(ifField="insurableInterest",matches={InsurableInterestConstants.OTHER},require ="insurableInterestReason",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.insurableInterestReason",groups = NonSingleNonMortgage.class),@FieldrequiredIf(ifField="firstAddress2",matches={NOT_EMPTY},require ="firstAddress1",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.firstAddress1",@FieldrequiredIf(ifField="firstAddress3",require ="firstAddress2",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.firstAddress2",@FieldrequiredIf(ifField="firstAddress4",require ="firstAddress3",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.firstAddress3",@FieldrequiredIf(ifField="firstAddress5",require ="firstAddress4",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.firstAddress4",@FieldrequiredIf(ifField="secondAddress2",require ="secondAddress1",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.secondAddress1",@FieldrequiredIf(ifField="secondAddress3",require ="secondAddress2",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.secondAddress2",@FieldrequiredIf(ifField="secondAddress4",require ="secondAddress3",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.secondAddress3",@FieldrequiredIf(ifField="secondAddress5",require ="secondAddress4",elseDisplay = "FieldrequiredIf.correspondenceDetailsForm.secondAddress4",groups=SecondLife.class)
})
public class CorrespondenceDetailsForm {
    ...
}

restructure

To simplify the above, I began to refactor several logical groups of these listed comments into a single custom comment: (@ firstlifecontactdetailsobserver and @ secondlifecontactdetailsobserver) This is the refactored class level comment:

@FieldrequiredIf.List({
    @FieldrequiredIf(ifField="lifeAssuredIsPolicyOwner",groups = NonSingleNonMortgage.class)
})
@FirstLifeContactDetailsObserver
@SecondLifeContactDetailsObserver
public class CorrespondenceDetailsForm {
    ...
}

This doesn't really improve the situation because I need a validator class for each new annotation

Is there a better cross domain verification method in spring MVC?

Solution

Just to complete the problem and tie it to a beautiful bow, two commentators mentioned in the Corrigendum that the front picture of the scene is actually the recommended way to implement cross field validations

Although it is certainly a design smell from the upward direction of spring MVC, it is not a problem for your code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>