首页 > 编程语言 > 详细

SpringBoot访问静态视图的两种方式

时间:2020-04-05 14:20:14      阅读:114      评论:0      收藏:0      [点我收藏+]

## 1 通过Controller控制跳转

package com.syu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {

  /*  @RequestMapping({"/","index.html"})
    public String index(){
        return "index";
    }*/
}

 

 

## 2 通过 WebMvcConfigurer

package com.syu.config;

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;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
    }

}

 

SpringBoot访问静态视图的两种方式

原文:https://www.cnblogs.com/lotus-wmm/p/12636708.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!