项目文件结构
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/");
}
}