springboot+thymeleaf模版通过ctroller层访问页面引入js css失效

本文解决了使用Themleaf引入css和js时路径错误导致无法访问static资源的问题,并提供了正确的路径写法,使得页面的css、js能成功引入。
@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能引入了

转载于:https://www.cnblogs.com/wkyhky/p/9358252.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值