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