2012-09-26 63 views
2

我想創建一個與Spring MVC簡單的導航,到目前爲止,我得到這個:Spring MVC的導航

@Controller 
@RequestMapping("/secure") 
public class NavigationController { 

    @ModelAttribute("myPath/operation") 
    public OperationForm getOperationForm() { 
     return new OperationForm(); 
    } 

    @RequestMapping("/myPath/operation") 
    public String processOperationPage() { 
     //Some logic goes here 
     return "myPath/operation"; 
    } 

    @ModelAttribute("myPath/configuration") 
    public ConfigurationForm getConfigurationForm() { 
     return new ConfigurationForm(); 
    } 

    @RequestMapping("/myPath/configuration") 
    public String processConfigurationPage(Map model) { 
     return "myPath/configuration"; 
    } 

} 

在我的JSP頁面:

<a href="${pageContext.servletContext.contextPath}/secure/myPath/configuration.htm" class="parent">Configuration</a> 
<a href="${pageContext.servletContext.contextPath}/secure/myPath/operation.htm" class="parent">Operation</a> 

這是解決方案,通過有效的網頁導航?你能否建議我使用其他方法來製作導航?我確信有但我在互聯網上找不到任何東西。

+0

是的,不管你是編碼導航的方式,但如果你想提高性能,增加對每個導航AJAX的支持。 –

回答

1

爲JSP的,這是一個有點整潔恕我直言:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
... 

<c:url var="config" value="/secure/myPath/configuration.htm"/> 

<a href="${config}" class="parent">Configuration</a>