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";
}
運行結果:

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
~~~~~完活
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Spring Data JPA的Audit功能審計數(shù)據庫的變更
數(shù)據庫審計是指當數(shù)據庫有記錄變更時,可以記錄數(shù)據庫的變更時間和變更人等,這樣以后出問題回溯問責也比較方便,本文討論Spring Data JPA審計數(shù)據庫變更問題,感興趣的朋友一起看看吧2021-06-06
解決Idea的選擇文件后定位瞄準器"Select Opened File"的功能
使用IntelliJ IDEA時,可能會發(fā)現(xiàn)"SelectOpenedFile"功能不見了,這個功能允許用戶快速定位到當前打開文件的位置,若要找回此功能,只需在IDEA的標題欄上右鍵,然后選擇"Always Select Opened File",這樣就可以重新啟用這個便捷的功能2024-11-11
Java中使用JavaMail多發(fā)郵件及郵件的驗證和附件實現(xiàn)
這篇文章主要介紹了Java中使用Java Mail多發(fā)郵件及郵件的驗證和附件實現(xiàn),包括在郵件中加入圖片等功能的實現(xiàn)講解,需要的朋友可以參考下2016-02-02

