利用Jsoup取出Html中的文字,去除所有的html标签,只保留字符

private static Whitelist whitelist = new Whitelist();

//最近的消息 内容
public static Map recentMessage(String content, Date createTime, boolean read, String messageType, String desc) {
   Map map = new HashMap<>();
   map.put("content", content.indexOf("<") > -1 && content.indexOf(">") > -1 ? Jsoup.clean(content, whitelist) : content);
   map.put("createTime", createTime);
   map.put("read", read);
   map.put("messageType", messageType);
   map.put("desc", desc);
   return map;
}

//关键方法: Jsoup.clean(String bodyHtml, Whitelist whitelist)

mave依赖:


    org.jsoup
    jsoup
    1.9.2

 

转载于:https://my.oschina.net/648885471/blog/2251850

你可能感兴趣的:(利用Jsoup取出Html中的文字,去除所有的html标签,只保留字符)