嗨,我目前正在开发一个 spring (3.2.x) 应用程序,我必须在其中将我的内容插入到由 id 指定的某个点的给定页面中。
这就是我目前正在做的事情:
@RequestMapping(value = "/{part}", method = RequestMethod.POST, produces="text/html")
@ResponseBody
public String enterModul(HttpServletRequest request, @PathVariable String part, @ModelAttribute Body body){
//body handling omitted
//getting the external html
String frame = restTemplate.getForObject("...externalUrl", String.class);
//getting my content
String uri = request.getRequestURL().toString();
String content = restTemplate.getForObject(uri, String.class);
// merge frame and content
String completeView = this.mergeFrameAndContent(frame, content);
return completeView;
}
@RequestMapping(value = "/{part}", method = RequestMethod.GET, produces="text/html")
@ResponseBody
public ModelAndView getInitialContentForPart(@PathVariable String part) {
//irrelevant code/model creation ommited
//just using InternalResourceViewResolver so nothing fancy here
ModelAndView view = new ModelAndView(part, "model", model);
return view;
}
private String mergeFrameAndContent(String frame, String content) {
//id identifies position
String view = frame.replace("id", content);
return view;
}
但不知何故,这样做感觉不对。有更好的解决方案吗?我试着用瓷砖 3 来做,但没有用。