在讀取數(shù)據(jù)庫这难,展示用戶圖片時舟误,出現(xiàn)如下代碼:
<p>![](/upload/loan/1495264907356.jpg) </p><p>![](/upload/loan/1495264918245.jpg) </p><p>![](/upload/loan/1495168081723.jpg) </p><p>![](/upload/loan/1495168059259.jpg) </p>null
改存儲夾雜空號字符。
而我需要的結(jié)果是:
<p>![](/upload/loan/1495264907356.jpg) </p><p>![](/upload/loan/1495264918245.jpg) </p><p>![](/upload/loan/1495168081723.jpg) </p><p>![](/upload/loan/1495168059259.jpg) </p>null
所以需要StringEscapeUtils類進行轉(zhuǎn)義與反轉(zhuǎn)義
demo如下:
import org.apache.commons.lang3.StringEscapeUtils;
public class TestAsyc {
public static void main(String[] args) {
String s = " <p>![](/upload/loan/1495264918245.jpg) </p>";
String content = StringEscapeUtils.unescapeHtml4(s);// 反轉(zhuǎn)義
System.out.println(content);
}
}
console:
<p>![](/upload/loan/1495264918245.jpg) </p>