2012-10-08 29 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

相关问题