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.del.OILService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
mvc的controller
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloudflix.feign.EnableFeignClients;
import t.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
~~~~~完活
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。