java - Optimal way to construct an instance from an http request parameters -
in project have:
a servlet handles http requests users profile info parameters, i.e (username = "bob" , password = "ugabaga", address = "blabla"... )
a user class represents user info. getters + setters : getname(), setname(string username)....
my question , there easy way create new user instance httprequest parameters?
something :
user newuser = createuserfromparams (new user(), httprequestparameters);
(without need write : user.setname(parameters.getparameter("username")) each of 30~ fields)
p.s - i'm not sending password, couldn't think of fieldname. passwords being sent sms's ;)
thanks in advance!
there httpservletrequest.getparametermap, delivers map<string, string[]> have `?a=1&a=2'. beanutils not do.
but can make own utility class using java reflection, or translate request parameters map<string, string> , use standard bean utility (apache).
Comments
Post a Comment