Spring Boot 2.0 设置网站默认首页

时间:2023-03-10 01:03:55
Spring Boot 2.0 设置网站默认首页

Spring Boot设置默认首页,方法实验OK如下

附上Application启动代码

/**
 * @ClassName Application
 * @Description Spring-Boot website启动类
 * @author kevin.tian
 * @Date 2018-03
 * @version 1.0.0
 */
@SpringBootApplication
@PropertySource(value={    
        "file:${APP_HOME_CONF}/overpayment-web/overpayment-web.properties",    
        "file:${APP_HOME_CONF}/overpayment-web/db.properties"
    })
@ImportResource({"file:${APP_HOME_CONF}/overpayment-web/spring.xml"})
public class Application extends SpringBootServletInitializer {

public static void main(String[] args)
    {
        try {
            SpringApplication.run(Application.class);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }
}

1. 放置默认首页default.html,

位置在/src/main/resources/static/default.html

2. 增加IndexController控制器,设置index路由

Spring Boot 2.0 设置网站默认首页

测试结果,如下

Spring Boot 2.0 设置网站默认首页