2016-09-19 38 views
1

解決HTML視圖我目前的工作代碼是這樣的如何在spring中加載html視圖?

<mvc:resources mapping="/static/**" location="/WEB-INF/static/html/" /> 
    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="" /> 
     <property name="suffix" value=".html" /> 
    </bean> 

,但我需要返回查看,如

​​

我怎樣才能使它這樣?

return "index"; 

回答

2

更改前綴爲/static/html/

 <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/static/html/" /> 
     <property name="suffix" value=".html" /> 
    </bean> 

所以,當你將返回爲"index"它會變成/static/html/index.html

+0

非常感謝我的努力。這解決了我的問題。保存我的一天.. –

3

,如果你使用的是春天開機,就會自動添加位於內的任何以下目錄的靜態Web資源:

/META-INF/resources/ 
/resources/ 
/static/ 
/public/ 

在消費的情況下,RESTful Web服務可能如果你把是一個好方法資源進入公共文件夾,這就是你的控制器應該是什麼樣子。

@Controller 
class Controller{ 

    @RequestMapping("/") 
    public String index() { 
     return "index.html"; 
    } 

} 
+0

謝謝@Priyamal。我不知道這件事。 –