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
일 을 끝내다
이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.

좋은 웹페이지 즐겨찾기