thymeleafjscss404问题
最近被thymeleaf 静态资源困扰,⼀直404,百度各种,⼤部分都是相同答案,并不能解决问题。现在贴出解决⽅案,希望能帮到同样问题的⼈。
@Controller
@RequestMapping("/home")
public class IndexController {
@RequestMapping("/index")
public ModelAndView index() {
ModelAndView modelAndView = new ModelAndView("/index");
return modelAndView;
}
}
<!-- Bootstrap -->
<link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}"  media="screen">
<link rel="stylesheet"  th:href="@{/bootstrap/css/bootstrap-responsive.min.css}"  media="screen">
<link rel="stylesheet" th:href="@{/vendors/easypiechart/jquery.easy-pie-chart.css}" media="screen">
<link rel="stylesheet"  th:href="@{/assets/styles.css}"  media="screen">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
thyme
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="lecode/svn/trunk/html5.js"></script>
<![endif]-->
<script  th:src="@{/vendors/modernizr-2.6.2-respond-1.1.0.min.js}"></script>
<!--/.fluid-container-->
<script type="text/javascript"  th:src="@{/vendors/jquery-1.9.1.min.js}"></script>
<script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/vendors/easypiechart/jquery.easy-pie-chart.js}"></script>
<script type="text/javascript" th:src="@{/assets/scripts.js}"></script>
解决⽅案如下
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/templates/");      registry.addResourceHandler("/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/static/");  super.addResourceHandlers(registry);
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。