好像是Spring Boot 2.0.4.RELEASE
中WebMvcConfigurerAdapter
已過時,所以想通過繼承WebMvcConfigurerAdapter來拓展SpringMvc的功能時會有一條刪除線。
因此,通過實現WebMvcConfigurer接口來拓展SpringMvc的功能()
package com.example.springboot.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration public class MyMvcConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) {
////瀏覽器發送 /nihao 請求來到 success registry.addViewController("/nihao").setViewName("success"); } }