您的位置:首頁技術文章
文章詳情頁

Springboot視圖解析器ViewResolver使用實例

瀏覽:2日期:2023-05-25 09:29:16

SpringMVC提供的ViewResolver可以分為兩大類:面向單一視圖和面向多視圖類型。所謂面向單一視圖指可通過視圖模板的位置來定位視圖,面向多視圖需要額外的配置文件來確定視圖。

項目結構如下(Idea)

Springboot視圖解析器ViewResolver使用實例

代碼

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@Configurationpublic 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; } }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
国产综合久久一区二区三区