2015-04-24 75 views
0

早上好! 我正在考虑在Spring MVC中使用Twitter Bootstrap。 我的问题是这样的:不要只导入Bootstrap文件并将它们声明在不同的文件jsp中?Twitter Bootstrap和Spring MVC

因为看看下面的页面https://samerabdelkafi.wordpress.com/2014/09/17/bootstrap-3/你看他们是如何注入依赖自举和jQuery(jar文件):

<dependency> 
    <groupId>org.webjars</groupId> 
    <artifactId>bootstrap</artifactId> 
    <version>3.2.0</version> 
    <exclusions> 
     <exclusion> 
      <groupId>org.webjars</groupId> 
      <artifactId>jquery</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency> 

<dependency> 
    <groupId>org.webjars</groupId> 
    <artifactId>jquery</artifactId> 
    <version>2.1.1</version> 
</dependency> 

然后用力的资源处理程序/ webjars/**将其与关联类路径:/ META-INF /资源/ webjars /地处引导-3.2.0.jar:

@EnableWebMvc 
@Configuration 
@ComponentScan(basePackages = { "com.mycompany.myproject.web.controller" }) 
public class MvcConfig extends WebMvcConfigurerAdapter { 

    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 
     registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); 
     registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); 
    } 
................. 

}

Jsp页面会有refe分配办法来引导:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
<head> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1"> 
    <link rel='stylesheet' href='webjars/bootstrap/3.2.0/css/bootstrap.min.css'> 
</head> 
<body> 

    <!-- YOUR CODE HERE --> 

<script type="text/javascript" src="webjars/bootstrap/3.2.0/js/bootstrap.min.js"></script> 
<script type="text/javascript" src="webjars/jquery/2.1.1/jquery.min.js"></script> 
</body> 
</html> 

总结我的问题是这样的:应采取何种路径添加到项目引导Spring MVC的?

感谢

+0

我会去没有webjars。但是,这又是我个人的看法。我不喜欢我的客户端依赖包作为罐子(不想添加一个不需要的附加层)。 – Yellen

回答

0

我不知道这是否是完全回答你的问题,这只是我个人的意见(主要是基于外部蒲公英数据表库除了自举处理),但我不喜欢webjars在所有。这是因为很多时候,现代JavaScript库通常会尝试自行处理依赖关系,并且Webjar可能会有点混淆。当你在webjars中声明某些内容并突然出现应用程序时,可能会出现这种情况:尝试从CDN或其他网页下载库。

添加更新版本的库更重要的是你必须执行(在你的情况下)额外的Maven构建。当你只是想切换到例如时,它有时是一种矫枉过正的行为。最小化版本。但这只是我个人的意见。