直接上代码:html
public class StaticResourcesConfig extends WebMvcConfigurerAdapter { private static final Log log = LogFactory.getLog(StaticResourcesConfig.class); @Override /** * 设置默认首页 */ public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("redirect:/index.html"); registry.setOrder(Ordered.HIGHEST_PRECEDENCE); super.addViewControllers(registry); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/path/**").addResourceLocations("file:/html/); } }
第二个方法能够添加静态资源映射,linux
在linux下,若是经过http://[server ip]/path/index.html进行访问,则能够访问到磁盘路径为 /html/index.html 的文件windows
在windows下则能够将代码中的 /html/ 换成 [盘符]:/html/ 如 D:/html/ide
提醒一下:spa
若是用的是容器,不要忘记目录映射code