1

我在新的 Spring MVC 3 应用程序中使用 Tiles 2。这是我的模板

  <definition name="baseLayout" template="/WEB-INF/jsp/layout/layout.jsp"  >
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/jsp/layout/header.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="userInfo" value="" />
        <put-attribute name="footer" value="/WEB-INF/jsp/layout/footer.jsp" />
    </definition>

和我的页面

<definition name="engageStep1View" extends="baseLayout"  >
        <put-attribute name="title" value="" />
        <put-attribute name="body" value="/WEB-INF/jsp/private/engageStep1.jsp" />
        <put-attribute name="userInfo" value="/layout/userInfo" />
</definition>

我在下一行添加到 tiles.xml 定义

<definition name="userInfoView" template="/WEB-INF/jsp/layout/userInfo.jsp"   />

enagageStep1 调用控制器有一个更好的主意:

  @RequestMapping(value = "/layout/userInfo")
    public ModelAndView handleRequest(ModelMap model) {

        ......
        MemberPrincipal memberPrincipal = (MemberPrincipal)authentication.getPrincipal();

        model.put("userName", memberPrincipal.getUserName());

        return new ModelAndView("userInfoView", "model", model);
    }

任何想法?

谢谢

4

1 回答 1

0

看起来您的 userInfo 控制器方法正在提供可能适用于您的整个应用程序/站点的信息。对于这种信息,您可以使用 spring 拦截器将所需的信息填充到当前属性上下文中。然后 userInfoView 可以根据需要使用此信息,而无需引用 userInfo 控制器方法。

另一种类似的方法是使用瓦片视图准备器。

于 2012-11-18T16:42:56.040 回答