欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot項目啟動自動跳轉到瀏覽器的操作代碼

 更新時間:2024年03月25日 11:00:49   作者:Bo~Sir  
這篇文章主要介紹了springboot項目啟動自動跳轉到瀏覽器的操作代碼,本文圖文實例代碼相結合給大家介紹的非常詳細,需要的朋友可以參考下

springboot 項目啟動自動打開瀏覽器訪問網(wǎng)站設置
在appcation.yml中添加以下代碼:

openProject:
  isOpen: true
  cmd: cmd /c start
  web:
    openUrl: http://localhost:8080

添加配置RunConfig類:

package com.example.demo.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RunConfig implements CommandLineRunner {
    @Value("${openProject.isOpen}")
    private boolean isOpen;
    @Value("${openProject.web.openUrl}")
    private String openUrl;
    @Value("${openProject.cmd}")
    private String cmd;
    @Override
    public void run(String... args){
        if(isOpen){
            String runCmd = cmd + " " + openUrl ;
            System.out.println("運行的命令: " + runCmd);
            Runtime run = Runtime.getRuntime();
            try {
                run.exec(runCmd);
                System.out.println("啟動瀏覽器打開項目成功");
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("啟動項目自動打開瀏覽器失敗");
            }
        }
    }
}

成功自動跳轉到登錄頁面:

到此這篇關于springboot項目啟動自動跳轉到瀏覽器的文章就介紹到這了,更多相關springboot項目啟動自動跳轉到瀏覽器內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論