一、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