例如,我有2页,左侧菜单和用于布局标签。左侧菜单的标签:
<%@tag description="Left panel" pageEncoding="UTF-8" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@attribute name="page" required="true"%>
<ul>
<!-- Dashboard -->
<li <c:if test="${page == 'dashboard'}">class="active"</c:if>>
<a href="<c:url value='/dashboard'/>">
<spring:message code="navigation.button.dashboard"/>
</a>
</li>
<!-- Settings -->
<li <c:if test="${page == 'settings'}">class="active"</c:if>>
<a href="<c:url value='/settings/'/>">
<spring:message code="navigation.button.settings"/>
</a>
</li>
</ul>
对于查看活动菜单,我使用变量页面,在我的所有弹簧控制器中,我设置了此模型属性,例如:
@Controller
@RequestMapping(value = "/settings")
public final class SettingController {
@ModelAttribute("page")
public final String getPage() { return "settings";}
@RequestMapping(value = "/")
public final String home(final Principal principal) {
if (principal == null) return "login";
return "settings";
}
}
对于页面标题我也使用了页面属性。我认为这不是最好的方法。也许有人知道动态视图活动菜单和页面标题的最佳方式吗?