java - How to convert underscore style query string into camel style property in a JavaBean in Spring MVC? -


for example, here's request:

get: /search?product_category=1&user_name=obama

i want define searchrequest accept query string, can use jsr 303 bean validation annotations validate parameters, below:

public class searchrequest {     @notempty(message="product category empty")     private int productcategory;     @notempty(message="user name empty")     private int username; } 

so, there @jsonproperty in jackson convert underscore style camel style?

you have 2 options;

first. have searchrequest pojo annotated values validation have controller post method receive pojo request body json/xml format.

public class searchrequest {     @notempty(message="product category empty")     private int productcategory;     @notempty(message="user name empty")     private int username; }  public string search(@requestbody @valid searchrequest search) {     ... } 

second. have validations in controller method signature eliminating validations in pojo can still use pojo if want.

public class searchrequest {      private int productcategory;      private int username; }  public string search(@requestparam("product_category") @notempty(message="product category empty") string productcategory, @requestparam("user_name") @notempty(message="user name empty") string username) {     ... // code set productcategory , username searchrequest pojo. } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -