不通過轉發直接訪問templates下文件的配置

項目文件結構



templates文件夾就相當於web-info文件夾,默認是不支持外部訪問的,只能同過內部轉發訪問,那如何開啓外部訪問呢?下面是配置類。

package com.changgou.web.item.config;

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

/**
 * @author :gzy
 * @date :Created in 2019/8/25
 * @description :
 * @version: 1.0
 */
@ControllerAdvice
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
      //映射路徑                                           //真實路徑
registry.addResourceHandler("/items/**").addResourceLocations("classpath:/templates/items/");
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章