今天在寫公司後臺管理系統,調用程序接口發現,返回值是php
<p><img src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444271696.png" _src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444271696.png"/></p><p><img src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444425034.png" _src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444425034.png"/></p><p><img src="wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444571207.png" _src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444571207.png"/></p><p><br/></p>
結果界面不顯示,還不理解這是啥,原來是轉義,藉助php函數htmlspecialchars_decode() 經粗略改寫 java實現html
static Map<String,String> html_specialchars_table = new Hashtable<String,String>(); static { html_specialchars_table.put("<","<"); html_specialchars_table.put(">",">"); html_specialchars_table.put("&","&"); html_specialchars_table.put(""","\""); } static String htmlspecialchars_decode(String s){ for (Map.Entry entry : html_specialchars_table.entrySet()) { Object key = entry.getKey( ); String val = html_specialchars_table.get(key); s = s.replaceAll(key.toString(), val); } return s; }
因爲使用的thymeleaf 引擎,因此必須使用標籤 th:utext ,java