第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

更改 Java 的 HTML 輸出

更改 Java 的 HTML 輸出

慕桂英546537 2023-09-18 16:34:55
我有以下代碼:@Controllerpublic class GatesController {    @RequestMapping ("/gates")    public static String qualityGates(String x) throws IOException {        try {            System.out.println("\n------QualityGates------");            URL toConnect = new URL(x);            HttpURLConnection con = (HttpURLConnection) toConnect.openConnection();            System.out.println("Sending 'GET' request to URL : " + x);            BufferedReader in = new BufferedReader(                    new InputStreamReader(con.getInputStream()));            String inputLine;            StringBuffer response = new StringBuffer();            while ((inputLine = in.readLine()) != null) {                response.append(inputLine);            }            in.close();            //Cast the JSON-File to a JSONObject            JSONObject res = new JSONObject(response.toString());            JSONArray gates = new JSONArray(res.getJSONObject("projectStatus").getJSONArray("conditions").toString());            JSONObject test = new JSONObject(res.getJSONObject("projectStatus").toString());            String a = ("\nThe current Project-Status is: " + test.get("status") + "\n");            String b = "";            for (int i = 0; i < gates.length(); i++) {                String status = gates.getJSONObject(i).getString("status");                String metric = gates.getJSONObject(i).getString("metricKey");                b = b + ("<\b>Status: " + status + " | Metric: " + metric);            }            System.out.println(a+b);            return a + b;        } catch (Exception e) {            System.out.println(e);            return String.format("Error");        }    }問(wèn)題是目前該網(wǎng)站如下所示:網(wǎng)站_當(dāng)前但我希望每個(gè)指標(biāo)都換行,而不是在一行中。正如您所看到的,我嘗試在字符串內(nèi)涵處添加 <\b> 您知道如何解決這個(gè)問(wèn)題嗎?這是我的第一個(gè)網(wǎng)絡(luò)應(yīng)用程序,我有點(diǎn)卡住了。我感謝每一個(gè)幫助!
查看完整描述

1 回答

?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

你的“<\b>”打破了它。如果刪除它并添加換行符“\n”,它應(yīng)該可以工作。像這樣:


String a = ("\nThe current Project-Status is: " + test.get("status") + "\n");

String b = "";

for (int i = 0; i < gates.length(); i++) {

   status = gates.getJSONObject(i).getString("status");

   String metric = gates.getJSONObject(i).getString("metricKey");

   b = b + ("Status: " + status + " | Metric: " + metric + "\n");

}

您還返回純文本。因此,要正確顯示它,請(qǐng)?zhí)砑印皃roducts =”text/plain”以返回格式化的字符串。


@GetMapping(value = "/gates", produces = "text/plain")

然后你的輸出將顯示換行符。這樣您就可以應(yīng)用進(jìn)一步的格式。


查看完整回答
反對(duì) 回復(fù) 2023-09-18
  • 1 回答
  • 0 關(guān)注
  • 117 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)