Springboot配置suffix指定mvc视图的后缀方法
程序员文章站
2022-06-25 23:17:51
springboot配置suffix指定mvc视图后缀如下所示:spring:#配置mvc视图后缀 mvc: view: suffix: ".html"配置指定后缀之后访问welco...
springboot配置suffix指定mvc视图后缀
如下所示:
spring: #配置mvc视图后缀 mvc: view: suffix: ".html"
配置指定后缀之后
访问welcome.html页面时只需要写“welcome”即可。
@controller public class democontroller { @getmapping("/a") public string demo(){ return "welcome"; }
运行结果:
springboot配置mvc-controller请求的后缀名
1.启动类添加配置
package com.ias.oil.client.schedule; import com.ias.oil.model.oilservice; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframework.boot.web.servlet.servletregistrationbean; import org.springframework.cloud.client.discovery.enablediscoveryclient; import org.springframework.cloud.netflix.feign.enablefeignclients; import org.springframework.context.annotation.bean; import org.springframework.web.servlet.dispatcherservlet; @enablediscoveryclient @enablefeignclients({oilservice.package_for_service_schedule}) @springbootapplication public class oilscheduleclientapplication { public static void main(string[] args) { springapplication.run(oilscheduleclientapplication.class, args); } /** * 设置匹配.action后缀的请求 * @param dispatcherservlet * @return */ @bean public servletregistrationbean servletregistrationbean(dispatcherservlet dispatcherservlet) { servletregistrationbean bean = new servletregistrationbean(dispatcherservlet); bean.addurlmappings("*.action"); return bean; } }
需要添加上面代码片段的此部分
/** * 设置匹配.action后缀的请求 * @param dispatcherservlet * @return */ @bean public servletregistrationbean servletregistrationbean(dispatcherservlet dispatcherservlet) { servletregistrationbean bean = new servletregistrationbean(dispatcherservlet); bean.addurlmappings("*.action"); return bean; }
2.配置文件中添加配置
spring: mvc: ##设置匹配.action后缀的请求的配置 pathmatch: use-suffix-pattern: false use-registered-suffix-pattern: true contentnegotiation: favor-path-extension: false
~~~~~完活
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
上一篇: 二叉堆(三)之 Java的实现
下一篇: 你那是高原反应