为了账号安全,请及时绑定邮箱和手机立即绑定

springboot如何设置默认的首页

/ 猿问

springboot如何设置默认的首页

波斯汪 2019-05-13 08:08:36

springboot如何设置默认的首页


查看完整描述

3 回答

?
慕丝7291255

1.spring boot中可以设置默认首页,当输入域名是可以自动跳转到默认指定的网页
@Configuration
public class DefaultView extends WebMvcConfigurerAdapter{

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}


 




查看完整回答
反对 回复 2019-05-14
?
慕仰8121524

@Configuration
public class CustomWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
private static Logger logger = Logger.getLogger();

@Override
public void addViewControllers(ViewControllerRegistry registry) {
String homePage = "";
try {
Properties props = PropertiesLoaderUtils.loadProperties(new ClassPathResource("application.cfg"));
homePage = props.getProperty("home.page");
} catch (IOException e) {
logger.error(e.getMessage());
homePage = "/index.html";
}

registry.addViewController("/").setViewName("redirect:" + homePage);
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}





查看完整回答
反对 回复 2019-05-14
?
慕雪6173905

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

@Configuration

public class CustomWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {

    private static Logger logger = Logger.getLogger();

 

    @Override

    public void addViewControllers(ViewControllerRegistry registry) {

        String homePage = "";

        try {

            Properties props = PropertiesLoaderUtils.loadProperties(new ClassPathResource("application.cfg"));

            homePage = props.getProperty("home.page");

        } catch (IOException e) {

            logger.error(e.getMessage());

            homePage = "/index.html";

        }

         

        registry.addViewController("/").setViewName("redirect:" + homePage);

        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);

        super.addViewControllers(registry);

    }

}

 




查看完整回答
反对 回复 2019-05-14

添加回答

回复

举报

0/150
提交
取消
意见反馈 邀请有奖 帮助中心 APP下载
官方微信