項目結構如下(Idea)
代碼
package com.syu.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.View; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.Locale; //若你想diy一些定制化的功能,只需要寫這個組件,然后將它交給SpringBoot //擴展SpringMVC dispatchservlet @Configuration public class MyMvcConfig implements WebMvcConfigurer { //ViewResolver 實現了試圖解析器的接口的類,我們就可以把它看作一個視圖解析器 @Bean public ViewResolver myViewResolver(){ return new MyViewResolver(); } public static class MyViewResolver implements ViewResolver{ @Override public View resolveViewName(String s, Locale locale) throws Exception { return null; } } }