我正在使用spring MVC开发MVC portlet。我想从相应的渲染映射方法将URL参数添加到打开页面的URL。 例如,对于此控制器类:
@Controller(value = "SpringMvcController")
@RequestMapping(value = "VIEW")
public class SpringMvcController {
@RenderMapping
public ModelAndView handleRenderRequest(RenderRequest request,RenderResponse response,Model model) {
ModelAndView modelAndView= new ModelAndView("view");
/*What should I add here*/
return modelAndView;
}
}
我想在打开view.jsp页面时按顺序添加一些代码,将参数添加到网址,如?param = value
这可能吗?
答案 0 :(得分:0)
您可以从请求中获取此参数,例如:
@RenderMapping
public ModelAndView handleRenderRequest(RenderRequest renderRequest, RenderResponse response, Model model) {
HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil
.getHttpServletRequest(renderRequest));
String param = ParamUtil.getString(request, "param");
...
}
答案 1 :(得分:0)
只需将参数添加到ModelAndView
对象,即可在.jsp
文件中访问它们:
<强> Controller.java:强>
@Controller(value = "SpringMvcController")
@RequestMapping(value = "VIEW")
public class SpringMvcController {
@RenderMapping
public ModelAndView handleRenderRequest(RenderRequest request,RenderResponse response,Model model) {
ModelAndView modelAndView= new ModelAndView("view");
modelAndView.addObject("objectName", object);
return modelAndView;
}
}
<强> SomeJspFile.jsp:强>
...
<p>${objectName}</p>
...
如果您创建自己的对象并创建了所有Getter和Setter,您甚至可以像这样访问此对象的属性:
<强> SomeJspFile.jsp:强>
...
<p>${objectName.attributeName}</p>
...