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)文章
java日期時間格式化@JsonFormat與@DateTimeFormat的使用
本文主要介紹了java日期時間格式化@JsonFormat與@DateTimeFormat的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-08-08
如何基于springcloud模擬RPC調(diào)用(Feign)
這篇文章主要介紹了如何基于springcloud模擬RPC調(diào)用(Feign),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-04-04
SpringBoot+Response如何統(tǒng)一返回result結(jié)果集
這篇文章主要介紹了SpringBoot+Response如何統(tǒng)一返回result結(jié)果集,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-05-05
Java的MyBatis框架項目搭建與hellow world示例
MyBatis框架為Java程序的數(shù)據(jù)庫操作帶來了很大的便利,這里我們就從最基礎(chǔ)的入手,來看一下Java的MyBatis框架項目搭建與hellow world示例,需要的朋友可以參考下2016-06-06
在Spring Boot中集成RabbitMQ詳細步驟(最新推薦)
本文將介紹如何在Spring Boot項目中集成RabbitMQ,實現(xiàn)生產(chǎn)者和消費者的基本配置,本文分步驟給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-12-12

