SpringBoot设置自动跳转前端界面

一般情况下,我们的Application启动文件的内容为一行的运行代码,默认启动项目以后不会自动跳转到我们的前端页面

java 复制代码
public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

这里我的可以通过设置文件的内容,将Application文件的内容粘贴为一下内容可以使项目启动后直接跳转到前端页面(注意更改自己的路径)

java 复制代码
public static void main(String[] args) {
        int port = 8080;
        String portPrefix = "--server.port=";
        for (String arg : args) {
            if (arg.startsWith(portPrefix)) {
                port = Integer.parseInt(arg.substring(portPrefix.length()));
            }
        }
        SpringApplication.run(SpringbootApplication.class, args);//注意更改成自己的路径
        try {
            Runtime.getRuntime().exec("cmd /c start http://localhost:" + port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
相关推荐
特立独行的猫A5 小时前
用仓颉语言 cj-tauri 框架,五分钟给娃做了个鸿蒙形近字游戏
java·后端·python
2分钟速写快排7 小时前
孔乙己的茴字有多少种写法?|AI 对话实时通信的三种实现
前端·javascript·github
码事漫谈8 小时前
我花了一周时间,看AI公司怎么"管"AI,结果越看越后背发凉
后端
Penge6668 小时前
JavaScript:BOM 详解
前端
Penge6669 小时前
Vite vs Webpack:前端构建工具原理与实战
前端
Penge6669 小时前
前端包管理工具:npm、Yarn、pnpm 快速入门
前端
Penge6669 小时前
Sass 了解
前端
Penge66610 小时前
Webpack 打包从 0 到 1 实战笔记
前端
Penge66610 小时前
Webpack 入门:是什么、为什么需要、怎么使用?
前端
Penge66610 小时前
Ant Design(Antd)了解
前端