I am considering using Spring MVC - how would I structure the fact that a page can consist of several different views? Consider a controller, which basically:
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<Post> posts = repository.getNewPosts(); return new ModelAndView("posts", "posts", posts); }
However, I decide that on every page I also need a third-party panel that displays data based on some logic. This βpanelβ will simply be β.jspβ, which will be included in the above βpostsβ view, and I can change my controller to:
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<Post> posts = repository.getNewPosts(); List<Items> items= repository.getItems(); return new ModelAndView("model", "model", new MyCommonViewModel(posts,items)); }
But then I would have to change each controller to do List<Items> items= repository.getItems(); , and again, change everything the next time I come up with something new.
It seems dirty. How to structure it?
`
source share