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