'Return custom jsp from controller
I need to implement a controller using Spring so that it sets appropriate jsp in ModelAndView object.
Let's put it that way. I made an API call to a server and got the order in which I need to render my View(like TitleView -> PriceView -> ReviewView). So I need to set view object which will follow that order. It may possible that api returns next order which is different from the previous one, in that situation it should set view object accordingly.
Note:- We are storing jsp for each component like Title, Price, Review somewhere in project directory.
@GetMapping("/product")
@ResponseBody
public ModelAndView process(@RequestParam...) {
// Getting order as string from API
List<String> order = api.getOrder(...);
// business logic
ContentModelAndView mav = new ContentModelAndView();
mav.addObject("obj", obj);
mav.setViewName(???)
// what should be the logic to setViewName so that we dynamically set the order.
return mav;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

