新聞中心
這篇文章主要介紹了springboot開發(fā)擴展springmvc實現(xiàn)解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
創(chuàng)新互聯(lián)專注于企業(yè)網(wǎng)絡(luò)營銷推廣、網(wǎng)站重做改版、建安網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5開發(fā)、商城系統(tǒng)網(wǎng)站開發(fā)、集團公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為建安等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
可以在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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
本文名稱:springboot開發(fā)擴展springmvc實現(xiàn)解析
本文鏈接:http://www.dlmjj.cn/article/ppdjjo.html


咨詢
建站咨詢
