从控制器返回自定义 jsp
我需要使用 Spring 实现一个控制器,以便它在 ModelAndView 对象中设置适当的 jsp。
这么说吧。我对服务器进行了 API 调用,并获取了渲染视图所需的顺序(如 TitleView -> PriceView -> ReviewView)。所以我需要设置遵循该顺序的视图对象。 api 可能会返回与前一个不同的下一个订单,在这种情况下,它应该相应地设置视图对象。
注意:- 我们将每个组件的 jsp 存储在项目目录中的某个位置,例如标题、价格、评论。
@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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论