1

I've read that adding @modelAttribute in method param binds the incoming data to the object and add it to the model object as attribute.

@RequestMapping(value = "/list", method = RequestMethod.GET) public String list(@ModelAttribute User user) { return "list"; } 

if this is accessed via /list?name=unnamed, in list.jsp "unnamed" can be seen using {user.name} because it was added as model attribute for list.jsp. This is very clear to me.

But if i do

@RequestMapping(value = "/list", method = RequestMethod.GET) public String list(User user) { return "list"; } 

"unnamed" can still be seen using {user.name} when accessed via /list?name=unnamed. I thought the user object will not be added into model because it does not have @ModelAttribute annotation.

2
  • It will still bind BUT as you state you cannot access it later on in your page (as it isn't model object) other things like accessing binding result and other features that do count for a @ModelAttribute annotated argument don't apply then. Commented May 5, 2017 at 5:37
  • Yes it will still bind but my problem is it is still being added as model attribute for the list.jsp which is not my expected behavior because it does not have @modelAttribute annotation. Commented May 6, 2017 at 15:14

1 Answer 1

0

Are you sure of this part of code: return "list"; ???

Seems you are returnig the String, not the object. Try it and post and both cases, I have no permissions to comment yet =\

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I am returning a jsp name and that will be resolved into a view as list.jsp. I am using spring framework.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.