java - How to validate Controller method argument in Spring with JSR validations? -
i validating form field given piece of code.
//controller method public string addbusiness(@valid @modelattribute("myform") myform myform, ...) { //logic go here. } //form @component public class myform{ @pattern(regexp = "[0-9]{3,10}", message = "should valid number") public string getzip_code() { homecoming this.zip_code; } }
now want same validation on zip_code
in method of controller like,
@requestmapping(value = "${validation.url}", method = requestmethod.get) @responsebody public list<string> getcitylist(@requestparam(value = "zip_code", required = true) final string zip_code) { //logic goes here }
how possible?
it's not. @valid
doesn't apply @requestparam
annotated parameters. can create custom handlermethodargumentresolver
or validation in method.
java spring validation controller arguments
No comments:
Post a Comment