2012-10-08 33 views
2

我開始在SpringMVC中構建基本應用程序。同時,我想使用一些易於設置的UI框架,如Twitter Bootstrap。但是,不知道如何設置它。將Spring Bootstrap集成到SpringMVC應用程序中

問:

  1. 我在哪裏放置下載的引導文件夾?

enter image description here

enter image description here enter image description here

我有什麼事這麼遠。

+0

我打算這麼做,你會告訴我你的使用Bootstrap和Spring MVC的經驗如何?問題是在這裏http://stackoverflow.com/questions/28732301/whats-the-best-method-to-implement-front-end-for-a-springmvc-application – Jack

回答

5

我會把這些放在src/main/resources下的不是在WEB-INF下。這些不需要保護。

此外,請確保您告訴Spring它們在您的調度程序servlet配置文件中,根據documentation

<mvc:resources mapping="/resources/**" location="/resources/" /> 

如果您使用的是Spring安全性,那麼您需要確保資源不受保護。

<http pattern="/resources/**" security="none"/> 
+0

如果我的資源位於webContent文件夾下,它會工作嗎?如果是的話,我怎麼能參考它? – larrytech

1

除非您打算編譯自定義css,否則不需要.less文件。 Maven項目,你通常將它們放在資源文件夾中。資源/資產/ css和資源/資產/ JS

在JSP:

<spring:url scope="page" var="bootstrapStylesheetUrl" value="/resources/assets/css/bootstrap.css"/> 
<spring:url scope="page" var="bootstrapResponsiveStylesheetUrl" value="/resources/assets/css/bootstrap-responsive.css"/> 
<spring:url scope="page" var="bootstrapJavascriptUrl" value="/resources/assets/js/bootstrap.js"/> 

然後在頭標記

<script src="${pageScope.bootstrapJavascriptUrl}"></script> 
<link rel="stylesheet" href="${pageScope.bootstrapStylesheetUrl}"/> 
<link rel="stylesheet" href="${pageScope.bootstrapResponsiveStylesheetUrl}"/> 

另外,不要忘記添加彈簧的taglib到你的JSP

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 

在Spring servlet上下文配置(productmgmt-servlet.xml中)的頂部添加一行:

<mvc:resources mapping="/resources/**" location="classpath:/"/> 
+0

檢查我的最新更新,看看這是你是什麼意思? – AppSensei

+0

彈簧標籤應該位於標籤的上方。另外,創建WEB-INF/js和css目錄。將/ boot下的bootstrapp css文件放在/ css中,將javascript放入/ js中。但是,這看起來是正確的。 – keaplogik

+0

另外,刪除media =「print」,這是我的錯誤。 – keaplogik

相關問題