spring boot 设置默认首页

2019-05-24  本文已影响0人  咪雅先森

进入一个项目的时候,发面输入的是 / 的话,没有跳到默认面上去。
请求地址,www.liukay.com 到指定页面。
在 spring boot 下,只需要添加一个配置就可以跳到默认页面。
测试发现,不加 forward 跳转不会成功。

在 shiro 下也正常。

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class DefaultView extends WebMvcConfigurerAdapter {

   @Override
   public void addViewControllers(ViewControllerRegistry registry) {

      registry.addViewController("/").setViewName("forward:/open/index");
       registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
       super.addViewControllers(registry);
   }
}
上一篇 下一篇

猜你喜欢

热点阅读