Springboot在Controller类上添加RequestMapping后静态资源找不到

时间:2021-07-07 18:38:28   收藏:0   阅读:108

 

技术分享图片

 

 

静态资源原来的路径上出现了RequestMapping("/admin")中的/admin

技术分享图片

 

 

这个时候添加添加一个配置类

package com.xzj.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //所有访问/admin/的都要去指定的位置下找资源
        registry.addResourceHandler("/admin/**").addResourceLocations("classpath:/static/");
    }

}

也可以使用

<html xmlns:th="http://www.thymeleaf.org" >
<script type="text/javascript" th:src="@{/js/jquery-1.8.2.min.js}"></script>

  解决

 

原文:https://www.cnblogs.com/xiezhijin/p/14982053.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!