Springboot配置suffix指定mvc視圖的后綴方法
更新時間:2021年07月02日 16:44:06 作者:綠頭龍
這篇文章主要介紹了Springboot配置suffix指定mvc視圖的后綴方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
Springboot配置suffix指定mvc視圖后綴
如下所示:
spring: #配置MVC視圖后綴 mvc: view: suffix: ".html"
配置指定后綴之后
訪問welcome.html頁面時只需要寫“welcome”即可。
@Controller public class demoController { @GetMapping("/a") public String demo(){ return "welcome"; }
運行結(jié)果:
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); } /** * 設(shè)置匹配.action后綴的請求 * @param dispatcherServlet * @return */ @Bean public ServletRegistrationBean servletRegistrationBean(DispatcherServlet dispatcherServlet) { ServletRegistrationBean bean = new ServletRegistrationBean(dispatcherServlet); bean.addUrlMappings("*.action"); return bean; } }
需要添加上面代碼片段的此部分
/** * 設(shè)置匹配.action后綴的請求 * @param dispatcherServlet * @return */ @Bean public ServletRegistrationBean servletRegistrationBean(DispatcherServlet dispatcherServlet) { ServletRegistrationBean bean = new ServletRegistrationBean(dispatcherServlet); bean.addUrlMappings("*.action"); return bean; }
2.配置文件中添加配置
spring: mvc: ##設(shè)置匹配.action后綴的請求的配置 pathmatch: use-suffix-pattern: false use-registered-suffix-pattern: true contentnegotiation: favor-path-extension: false
~~~~~完活
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java?POI導出Excel時合并單元格沒有邊框的問題解決
這篇文章主要給大家介紹了關(guān)于Java?POI導出Excel時合并單元格沒有邊框的問題解決辦法,文中通過代碼介紹的非常詳細,對大家學習或者使用java具有一定的參考學習價值,需要的朋友可以參考下2023-07-07SpringBoot配置類中@Configuration和@Bean的作用
這篇文章主要介紹了SpringBoot配置類中@Configuration和@Bean的作用,@Configuration 指明當前類是一個配置類來替代之前的Spring配置文件,Spring boot的配置類,相當于Spring的配置文件,需要的朋友可以參考下2023-11-11解析Mybatis SqlSessionFactory初始化原理
本文主要介紹了Mybatis SqlSessionFactory初始化原理,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學習學習吧2021-07-07劍指Offer之Java算法習題精講二叉樹的構(gòu)造和遍歷
跟著思路走,之后從簡單題入手,反復去看,做過之后可能會忘記,之后再做一次,記不住就反復做,反復尋求思路和規(guī)律,慢慢積累就會發(fā)現(xiàn)質(zhì)的變化2022-03-03解決spring-integration-mqtt頻繁報Lost connection錯誤問題
這篇文章主要介紹了解決spring-integration-mqtt頻繁報Lost connection錯誤問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03