工具 API

2021-08-11 10:42:46 浏览数 (2)

过滤Html标签

代码语言:javascript复制
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;

public class HtmlUtil {

	/**
	 *
	 * @param content
	 * @return
	 */
	public final static String cleanHtml(String content) {
		if (StringUtils.isBlank(content)) {
			return "";
		}

		content = StringEscapeUtils.unescapeHtml4(content);
		content = Jsoup.clean(content, Whitelist.none());
		content = StringEscapeUtils.unescapeHtml4(content).replaceAll(" ", "").trim();
		content = StringEscapeUtils.unescapeJava(content);
		return content;
	}
}

读取配置文件

代码语言:javascript复制
public class PropertiesTest {

    public static void main(String[] args) throws Exception{

        Properties properties = new Properties();
        properties.load(PropertiesTest.class.getClassLoader().getResourceAsStream("application.properties"));

        System.out.println(properties.getProperty("bean"));
    }
}

application.properties文件:
    bean= "application.properties"
    
输出:"application.properties"

0 人点赞