不通过转发直接访问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/");
    }
}

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