springboot+thymeleaf模版通过ctroller层访问页面引入js css失效
@RestController @RequestMapping("dsd") public class DataController extends BaseController { @RequestMapping("toindex") public ModelAndView toindex(Model model){ /* model.addAttribute("moudels",dataService.index()); model.addAttribute("question",dataService.question()); model.addAttribute("information",dataService.information()); model.addAttribute("rank",dataService.indexRank());*/ return new ModelAndView("index"); }
如果是以为加上了它所以访问不到static下的资源了,这是应为你用themleaf引入css和js时的路径写错了,应该在你写的路径前加上/
<link th:href="@{/css/index.css}" rel="stylesheet"> <link rel="stylesheet" th:href="@{/css/header.css}"> <link rel="shortcut icon" th:href="@{/images/login.ico}" type="image/x-icon"> <link rel="stylesheet" th:href="@{/font-awesome-4.7.0/css/font-awesome.min.css}">
这样加上后,就会发现页面的css,js能引入了