java - Spring MVC similar setters -
i have 2 classes string title
field. have similar setters called settitle()
. when use them object parameters in post request, field values rewrite new values in foo , bar. foo populates in controller
before request.
public class foo{ // ... string title; public void settitle(string title){ this.title=title; // ... } public class bar { // ... string title; public void settitle(string title){ this.title=title; // ... } } @modelattribute public void populatefoo(model model){ foo foo = foo.getfromdb() model.addattribute(foo); } @requestmapping public string somepost(foo foo, bar bar, ...){ bar newbar = new bar(); newbar.settitle(bar.gettitle()); }
when i'm invoking settitle()
on newbar
, method settitle()
on foo
invoked.
there no simple way spring mvc distinguish unfortunately - if submit field name title
complex types have setter title
set. 1 place dto may help, type encompasses fields both types , instantiates foo
or bar
appropriately.
Comments
Post a Comment