Springboot配置suffix指定mvc视图的后缀方法

网友投稿 234 2022-12-31

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(dispaVtwlCezNwtcherServlet);

bean.addUrlMappings("*.action");

return bean;

}

2.配置文件中添加配置

spring:

mvc:

##设置匹配.action后缀的请求的配置

pathmatch:

use-suffix-pattern: false

use-registered-suffix-pattern: true

contentnegotiation:

favor-path-extension: false

~~~~~完活

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:网站api接口文档(网站api对接)
下一篇:解决Swagger2返回map复杂结构不能解析的问题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~