SpringBoot配置启动页(首页)控制台打印项目访问入口url

一、SpringBootApplication

 1 package com.reliable.yang;
 2 
 3 /**
 4  * @author Administrator
 5  * @date 2022-06-20 16:32
 6  */
 7 import lombok.extern.slf4j.Slf4j;
 8 import org.springframework.boot.SpringApplication;
 9 import org.springframework.boot.autoconfigure.SpringBootApplication;
10 import org.springframework.context.ConfigurableApplicationContext;
11 import org.springframework.core.env.Environment;
12 import org.springframework.util.StringUtils;
13 
14 import java.net.InetAddress;
15 import java.net.UnknownHostException;
16 @Slf4j
17 @SpringBootApplication
18 public class BlogApp {
19     public static void main(String[] args) throws UnknownHostException, UnknownHostException {
20         ConfigurableApplicationContext application = SpringApplication.run(BlogApp.class, args);
21         log.info("..######..##.....##..######...######..########..######...######.\n" +
22                 ".##....##.##.....##.##....##.##....##.##.......##....##.##....##\n" +
23                 ".##.......##.....##.##.......##.......##.......##.......##......\n" +
24                 "..######..##.....##.##.......##.......######....######...######.\n" +
25                 ".......##.##.....##.##.......##.......##.............##.......##\n" +
26                 ".##....##.##.....##.##....##.##....##.##.......##....##.##....##\n" +
27                 "..######...#######...######...######..########..######...######.");
28         Environment env = application.getEnvironment();
29         String ip = InetAddress.getLocalHost().getHostAddress();
30         String port = env.getProperty("server.port");
31         String path = env.getProperty("server.servlet.context-path");
32         if (StringUtils.isEmpty(path)) {
33             path = "";
34         }
35         log.info("\n----------------------------------------------------------\n\t" +
36                 "Application  is running! Access URLs:\n\t" +
37                 "Local访问网址: \t\thttp://localhost:" + "8080" + path + "\n\t" +
38 //                "External访问网址: \thttp://" + ip + ":" + port + path + "\n\t" +
39                 "----------------------------------------------------------");
40     }
41 }

二、application.properties

1 server.port= 8888
2 server.servlet.context-path=/

 三、controller

1 @Controller
2 
3 public class IndexController {
4     @RequestMapping("/")
5     public String homePage() {
6         return "login.html"; // login.html 需要在static目录下
7     }
8 }

效果如图:

参考:https://www.hangge.com/blog/cache/detail_2528.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

靠谱杨

感谢您的认可和鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值