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


 

 

 

静态资源原来的路径上出现了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>

  解决

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM