Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AddAllAttributes method spring mvc

I have two lists

List<User> list_of_users=new ArrayList<User>();
List<String> list_of_attributes=new ArrayList<String>();

When i try to use the following lines of code:

model.addAttribute("takeattributes",list_of_users);
model.addAttribute("takeattributes",list_of_attributes);

I realise that it keeps only the second list (list_of_attributes) and the first deleted. I was wondering how to keep both of these two lists in the model.Is this possible to be happened?Is the AddAllAttributes method what i need?If yes can anyone explain me how the AddAllAttributes method is working.I look at the spring mvc documentation but i didn't really understand.

like image 435
Nick Robertson Avatar asked Jan 19 '26 12:01

Nick Robertson


1 Answers

The model is essentially a Map with unique keys. You really should define two unique keys:

model.addAttribute("users", list_of_users);
model.addAttribute("attributes", list_of_attributes);

The first argument serves as the identifier to which you can reference each respective list in your GUI.

like image 78
Johan Sjöberg Avatar answered Jan 22 '26 02:01

Johan Sjöberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!