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

springboot如何设置默认的首页

/ 猿问

springboot如何设置默认的首页

幕布斯6054654 2019-03-11 08:08:49

springboot如何设置默认的首页


查看完整描述

2 回答

?
慕桂英546537

@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-03-20
?
莫回无

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-03-20

添加回答

回复

举报

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