You can create your method with ModelAndView as return type.
ModelAndView mav = new ModelAndView();
mav.setViewName("welcomePage");
mav.addObject("list", list);
mav.addObject("list2", list2);
return mav
In that mav object you can add n number of models.
And on jsp you can access them using ${list}, ${list2}
.
@Data
@Builder
class Main {
public List<List<Object>> getList() {
List<List<Object>> list = new ArrayList<>();
list.add(Arrays.asList(new A[]{new A("A"), new A("A1"), new A("A2")}));
list.add(Arrays.asList(new B[]{new B("B"), new B("B1"), new B("B2")}));
return list;
}
}
class A {
String name;
public A(String name) {
this.name = name;
}
}
class B {
String name;
public B(String name) {
this.name = name;
}
}
>` Also you can use ModelAndView object and add all model inside of it.
– Sagar Gangwal Aug 23 '20 at 20:50