我试图在单个请求中返回多个视图,并以 JSON 字符串形式返回它们。
Example:
@RequestMapping(value = "my-request")
public void myRequest(HttpServletRequest request, HttpServletResponse response) throws Exception
{
Map<String,Object> model1 = new Hashtable<String,Object>();
model1.put(...);
ModelAndView modelAndView1 = new ModelAndView("path/to/view1", model1);
// Render modelAndView1 in some way, in order to obtain the rendered HTML as a String
Map<String,Object> model2 = new Hashtable<String,Object>();
model2.put(...);
ModelAndView modelAndView2 = new ModelAndView("path/to/view2", model2);
// Render modelAndView2 in some way, in order to obtain the rendered HTML as a String
// Now write a JSON String to the HttpServletResponse containing both the rendered views (strings).
// (this is not part of my problem, I'm able to do it as long as I have the two strings)
}
我正在使用 Spring MVC 和 Tiles 2。
谁能帮我?
Update 1- 视图名称使用ViewResolver
:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/tiles/" />
<property name="suffix" value=".jsp" />
</bean>
Update 2- 我创建了一个github 存储库 https://github.com/MintTwist/ViewResolver-test包含一个重现问题的很小的例子。