在读取数据库,展示用户图片时,出现如下代码:
<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
改存储夹杂空号字符。
而我需要的结果是:
<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类进行转义与反转义
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);// 反转义
System.out.println(content);
}
}
console:
<p>![](/upload/loan/1495264918245.jpg) </p>