ViewResolver -Springboot中的視圖解析器


項目結構如下(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;
        }
    }
}

 


免責聲明!

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



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