Springboot 實現WebMvcConfigurer接口來拓展SpringMvc的功能


好像是Spring Boot 2.0.4.RELEASEWebMvcConfigurerAdapter已過時,所以想通過繼承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"); } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM