博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring boot 默认静态资源路径与手动配置访问路径的方法
阅读量:6893 次
发布时间:2019-06-27

本文共 1219 字,大约阅读时间需要 4 分钟。

这篇文章主要介绍了Spring boot 默认静态资源路径与手动配置访问路径的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下
 

在application.propertis中配置

##端口号server.port=8081##默认前缀spring.mvc.view.prefix=/## 响应页面默认后缀spring.mvc.view.suffix=.html# 默认值为 /**spring.mvc.static-path-pattern=/**# 这里设置要指向的路径,多个使用英文逗号隔开,默认值为 classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/spring.resources.static-locations= classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/****/

如果自定义访问路径则需要添加WebConfig配置类

package com.dakewang.config;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;/** * 手动配置静态资源路径 *  */@Configurationpublic class WebConfig extends WebMvcConfigurerAdapter{  @Override  public void configurePathMatch(PathMatchConfigurer configurer) {    configurer.setUseSuffixPatternMatch(false).        setUseTrailingSlashMatch(true);  }}

在controller中

/** * 跳转index.html页面 * @return */@RequestMapping("/index")public String indexHtml() {  return "index";}

在浏览器中访问地址

localhost:8081/index

转载于:https://www.cnblogs.com/wlsblog/p/8046015.html

你可能感兴趣的文章
go get报错 error: RPC failed; result=56, HTTP code =
查看>>
串行(Sequential)、并发(Concurrent)、并行(parallel)与分布式
查看>>
JAVA NIO学习笔记之Channel(基础篇)
查看>>
Xcode升级到6.4之后插件无法使用,重新安装最新也无法使用的解决办法
查看>>
秒懂科技新概念
查看>>
eclipse启动tomcat无法访问
查看>>
Notepad++ 书签
查看>>
TiDB 集群测试
查看>>
十天学会php之第五天
查看>>
Java基础10
查看>>
jquery基础学习二
查看>>
为什么说写“安装指南”类博客的程序员是懒惰的
查看>>
Android模拟器——Genymotion(很快)
查看>>
学习规划
查看>>
SpringMVC项目使用Thymeleaf模板引擎
查看>>
定义和使用SQL变量
查看>>
12.21 php-fpm的pool12.22 php-fpm慢执行日志12.23 open_basedir12.24 php-fpm进程管理
查看>>
Supervisor进程管理软件的安装与配置
查看>>
细谈 vue - transition 篇
查看>>
Ubuntn中获取仓库中的工具源码与构建
查看>>