springboot開發(fā)擴展springmvc實現(xiàn)解析
這篇文章主要介紹了springboot開發(fā)擴展springmvc實現(xiàn)解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
可以在Java定義自己配置的springmvc:
MyMvcConfig.java
package com.gong.springbootcurd.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; //@EnableWebMvc 接管springmvc @Configuration public class MyMvcConfig implements WebMvcConfigurer{ @Override public void addViewControllers(ViewControllerRegistry registry) { //瀏覽器發(fā)送gong請求會跳轉(zhuǎn)到/templates/success.html頁面 registry.addViewController("gong").setViewName("success"); } //所有的WebMvcConfigurer會一起起作用 //將組件注冊到容器中 @Bean public WebMvcConfigurer webMvcConfigurer() { WebMvcConfigurer webMvcConfigurer = new WebMvcConfigurer(){ public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); registry.addViewController("/index.html").setViewName("index"); } }; return webMvcConfigurer; } }
關(guān)鍵有三點:
(1)實現(xiàn)WebMvcConfigurer。
(2)用Configuration標識配置類。
(3)如果是public WebMvcConfigurer webMvcConfigurer() {...},則需要用@Bean標識。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解使用Spring的BeanPostProcessor優(yōu)雅的實現(xiàn)工廠模式
這篇文章主要介紹了詳解使用Spring的BeanPostProcessor優(yōu)雅的實現(xiàn)工廠模式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-07-07springboot集成shiro權(quán)限管理簡單實現(xiàn)
這篇文章主要介紹了springboot集成shiro權(quán)限管理簡單實現(xiàn),文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-08-08基于Spring中的事務(wù)@Transactional細節(jié)與易錯點、幻讀
這篇文章主要介紹了基于Spring中的事務(wù)@Transactional細節(jié)與易錯點、幻讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11Java 實戰(zhàn)項目錘煉之在線購書商城系統(tǒng)的實現(xiàn)流程
讀萬卷書不如行萬里路,只學書上的理論是遠遠不夠的,只有在實戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+jsp+mysql+servlet+ajax實現(xiàn)一個在線購書商城系統(tǒng),大家可以在過程中查缺補漏,提升水平2021-11-11Java并發(fā)編程Callable與Future的應(yīng)用實例代碼
這篇文章主要介紹了Java并發(fā)編程Callable與Future的應(yīng)用實例代碼,具有一定借鑒價值,需要的朋友可以參考下2018-01-01