早上好! 我正在考虑在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的?
感谢
我会去没有webjars。但是,这又是我个人的看法。我不喜欢我的客户端依赖包作为罐子(不想添加一个不需要的附加层)。 – Yellen