Replace HTML tags, keep Spaces, before there is such a requirement, through Baidu to find a method, very easy to use, record.

Public static String convert(String HTML) {if (stringutils.isempty (HTML)) { return ""; } Document document = Jsoup.parse(html); Document.OutputSettings outputSettings = new Document.OutputSettings().prettyPrint(false); document.outputSettings(outputSettings); document.select("br").append("\\n"); document.select("p").prepend("\\n"); document.select("p").append("\\n"); String newHtml = document.html().replaceAll("\\\\n", "\n"); String plainText = Jsoup.clean(newHtml, "", Whitelist.none(), outputSettings); String result = StringEscapeUtils.unescapeHtml(plainText.trim()); return result; <dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.11.3</version> </dependency> <dependency> <groupId>commons-lang</ artifactId> <version>2.6</version> </dependency> </dependencies>Copy the code