public static void main(String[] args) {
String str = "thi is a test 这是一个测试";
String xml = "\n" +
"\n" +
" \n" +
" 张 三 \n" +
" 26 \n" +
" \n" +
" \n" +
" 李四 \n" +
" 25 \n" +
" \n" +
" ";
System.out.println("用escapeJava方法转义之后的字符串为:" + StringEscapeUtils.escapeJava(str));
System.out.println("用unescapeJava方法反转义之后的字符串为:" + StringEscapeUtils.unescapeJava(StringEscapeUtils.escapeJava(str)));
System.out.println("用escapeHtml方法转义之后的字符串为:" + StringEscapeUtils.escapeHtml(str));
System.out.println("用unescapeHtml方法反转义之后的字符串为:" + StringEscapeUtils.unescapeHtml(StringEscapeUtils.escapeHtml(str)));
System.out.println("用escapeXml方法转义之后的字符串为:" + StringEscapeUtils.escapeXml(xml));
System.out.println("用unescapeXml方法反转义之后的字符串为:" + StringEscapeUtils.unescapeXml(StringEscapeUtils.escapeXml(xml)));
System.out.println("用escapeJavaScript方法转义之后的字符串为:" + StringEscapeUtils.escapeJavaScript(str));
System.out.println("用unescapeJavaScript方法反转义之后的字符串为:" + StringEscapeUtils.unescapeJavaScript(StringEscapeUtils.unescapeJavaScript(str)));
}
"C:\Program Files\Java\jdk1.8.0_171\bin\java.exe" "-javaagent:C:\software_work\JetBrains\IntelliJ IDEA 2018.1.2\lib\idea_rt.jar=62756:C:\software_work\JetBrains\IntelliJ IDEA 2018.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_171\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\rt.jar;D:\asiainfo\group-center\group-system\group-system-service\target\classes;D:\asiainfo\group-center\group-common\common-api\target\classes;D:\asiainfo\datas\maven_lib\org\thymeleaf\thymeleaf\3.0.5.RELEASE\thymeleaf-3.0.5.RELEASE.jar;D:\asiainfo\datas\maven_lib\ognl\ognl\3.1.12\ognl-3.1.12.jar;D:\asiainfo\datas\maven_lib\org\javassist\javassist\3.21.0-GA\javassist-3.21.0-GA.jar;D:\asiainfo\datas\maven_lib\org\attoparser\attoparser\2.0.3.RELEASE\attoparser-2.0.3.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\unbescape\unbescape\1.1.4.RELEASE\unbescape-1.1.4.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\thymeleaf\thymeleaf-spring4\3.0.5.RELEASE\thymeleaf-spring4-3.0.5.RELEASE.jar;D:\asiainfo\datas\maven_lib\nz\net\ultraq\thymeleaf\thymeleaf-layout-dialect\2.2.1\thymeleaf-layout-dialect-2.2.1.jar;D:\asiainfo\datas\maven_lib\org\codehaus\groovy\groovy\2.4.13\groovy-2.4.13.jar;D:\asiainfo\datas\maven_lib\nz\net\ultraq\thymeleaf\thymeleaf-expression-processor\1.1.2\thymeleaf-expression-processor-1.1.2.jar;D:\asiainfo\datas\maven_lib\org\apache\commons\commons-lang3\3.1\commons-lang3-3.1.jar;D:\asiainfo\datas\maven_lib\commons-io\commons-io\2.4\commons-io-2.4.jar;D:\asiainfo\datas\maven_lib\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar;D:\asiainfo\datas\maven_lib\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\asiainfo\datas\maven_lib\javax\mail\mail\1.4.7\mail-1.4.7.jar;D:\asiainfo\datas\maven_lib\javax\activation\activation\1.1.1\activation-1.1.1.jar;D:\asiainfo\datas\maven_lib\com\yahoo\platform\yui\yuicompressor\2.3.6\yuicompressor-2.3.6.jar;D:\asiainfo\datas\maven_lib\org\apache\poi\poi\3.12\poi-3.12.jar;D:\asiainfo\datas\maven_lib\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-web\4.3.14.RELEASE\spring-web-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-webmvc\4.3.14.RELEASE\spring-webmvc-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-jdbc\4.3.14.RELEASE\spring-jdbc-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-tx\4.3.14.RELEASE\spring-tx-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-context\4.3.14.RELEASE\spring-context-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-context-support\4.3.8.RELEASE\spring-context-support-4.3.8.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\boot\spring-boot\1.5.10.RELEASE\spring-boot-1.5.10.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\mybatis\mybatis\3.4.5\mybatis-3.4.5.jar;D:\asiainfo\datas\maven_lib\org\mybatis\mybatis-spring\1.3.1\mybatis-spring-1.3.1.jar;D:\asiainfo\datas\maven_lib\com\alibaba\fastjson\1.2.31\fastjson-1.2.31.jar;D:\asiainfo\datas\maven_lib\com\fasterxml\jackson\core\jackson-databind\2.8.10\jackson-databind-2.8.10.jar;D:\asiainfo\datas\maven_lib\com\fasterxml\jackson\core\jackson-annotations\2.8.0\jackson-annotations-2.8.0.jar;D:\asiainfo\datas\maven_lib\com\fasterxml\jackson\core\jackson-core\2.8.10\jackson-core-2.8.10.jar;D:\asiainfo\datas\maven_lib\com\fasterxml\jackson\dataformat\jackson-dataformat-xml\2.8.4\jackson-dataformat-xml-2.8.4.jar;D:\asiainfo\datas\maven_lib\com\fasterxml\jackson\module\jackson-module-jaxb-annotations\2.8.7\jackson-module-jaxb-annotations-2.8.7.jar;D:\asiainfo\datas\maven_lib\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;D:\asiainfo\datas\maven_lib\com\fasterxml\woodstox\woodstox-core\5.0.2\woodstox-core-5.0.2.jar;D:\asiainfo\datas\maven_lib\com\github\jknack\handlebars-springmvc\1.3.1\handlebars-springmvc-1.3.1.jar;D:\asiainfo\datas\maven_lib\com\github\jknack\handlebars\1.3.1\handlebars-1.3.1.jar;D:\asiainfo\datas\maven_lib\org\antlr\antlr4-runtime\4.2.2\antlr4-runtime-4.2.2.jar;D:\asiainfo\datas\maven_lib\org\antlr\antlr4-annotations\4.2.2\antlr4-annotations-4.2.2.jar;D:\asiainfo\datas\maven_lib\org\mozilla\rhino\1.7R4\rhino-1.7R4.jar;D:\asiainfo\datas\maven_lib\com\github\jknack\handlebars-jackson2\1.3.1\handlebars-jackson2-1.3.1.jar;D:\asiainfo\datas\maven_lib\com\alibaba\boot\dubbo-spring-boot-starter\0.1.0\dubbo-spring-boot-starter-0.1.0.jar;D:\asiainfo\datas\maven_lib\com\alibaba\dubbo\2.6.1\dubbo-2.6.1.jar;D:\asiainfo\datas\maven_lib\org\jboss\netty\netty\3.2.5.Final\netty-3.2.5.Final.jar;D:\asiainfo\datas\maven_lib\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.jar;D:\asiainfo\datas\maven_lib\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;D:\asiainfo\datas\maven_lib\com\google\guava\guava\16.0.1\guava-16.0.1.jar;D:\asiainfo\datas\maven_lib\com\alibaba\boot\dubbo-spring-boot-autoconfigure\0.1.0\dubbo-spring-boot-autoconfigure-0.1.0.jar;D:\asiainfo\datas\maven_lib\com\alibaba\boot\dubbo-spring-boot-actuator\0.1.0\dubbo-spring-boot-actuator-0.1.0.jar;D:\asiainfo\group-center\group-common\common-dao\target\classes;D:\asiainfo\datas\maven_lib\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar;D:\asiainfo\datas\maven_lib\com\alibaba\druid-spring-boot-starter\1.1.6\druid-spring-boot-starter-1.1.6.jar;D:\asiainfo\datas\maven_lib\com\alibaba\druid\1.1.6\druid-1.1.6.jar;D:\asiainfo\datas\maven_lib\org\springframework\boot\spring-boot-autoconfigure\1.5.10.RELEASE\spring-boot-autoconfigure-1.5.10.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.1\mybatis-spring-boot-starter-1.3.1.jar;D:\asiainfo\datas\maven_lib\org\springframework\boot\spring-boot-starter-jdbc\1.5.10.RELEASE\spring-boot-starter-jdbc-1.5.10.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\apache\tomcat\tomcat-jdbc\8.5.27\tomcat-jdbc-8.5.27.jar;D:\asiainfo\datas\maven_lib\org\apache\tomcat\tomcat-juli\8.5.27\tomcat-juli-8.5.27.jar;D:\asiainfo\datas\maven_lib\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.1\mybatis-spring-boot-autoconfigure-1.3.1.jar;D:\asiainfo\group-center\group-system\group-system-api\target\classes;D:\asiainfo\datas\maven_lib\org\springframework\boot\spring-boot-starter-aop\1.5.10.RELEASE\spring-boot-starter-aop-1.5.10.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\boot\spring-boot-starter\1.5.10.RELEASE\spring-boot-starter-1.5.10.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\boot\spring-boot-starter-logging\1.5.10.RELEASE\spring-boot-starter-logging-1.5.10.RELEASE.jar;D:\asiainfo\datas\maven_lib\ch\qos\logback\logback-classic\1.1.11\logback-classic-1.1.11.jar;D:\asiainfo\datas\maven_lib\ch\qos\logback\logback-core\1.1.11\logback-core-1.1.11.jar;D:\asiainfo\datas\maven_lib\org\slf4j\jcl-over-slf4j\1.7.25\jcl-over-slf4j-1.7.25.jar;D:\asiainfo\datas\maven_lib\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\asiainfo\datas\maven_lib\org\slf4j\log4j-over-slf4j\1.7.25\log4j-over-slf4j-1.7.25.jar;D:\asiainfo\datas\maven_lib\org\yaml\snakeyaml\1.17\snakeyaml-1.17.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-aop\4.3.14.RELEASE\spring-aop-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\aspectj\aspectjweaver\1.8.10\aspectjweaver-1.8.10.jar;D:\asiainfo\datas\maven_lib\org\springframework\security\spring-security-core\4.2.4.RELEASE\spring-security-core-4.2.4.RELEASE.jar;D:\asiainfo\datas\maven_lib\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-beans\4.3.14.RELEASE\spring-beans-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-core\4.3.14.RELEASE\spring-core-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\org\springframework\spring-expression\4.3.14.RELEASE\spring-expression-4.3.14.RELEASE.jar;D:\asiainfo\datas\maven_lib\com\ai\woego\boot\cache-engine-spring-boot-autoconfigure\1.0.1-SNAPSHOT\cache-engine-spring-boot-autoconfigure-1.0.1-SNAPSHOT.jar;D:\asiainfo\datas\maven_lib\com\ai\woego\boot\config-engine-spring-boot-autoconfigure\1.0.1-SNAPSHOT\config-engine-spring-boot-autoconfigure-1.0.1-SNAPSHOT.jar;D:\asiainfo\datas\maven_lib\com\ai\paas\config-engine\2.0.1-SNAPSHOT\config-engine-2.0.1-SNAPSHOT.jar;D:\asiainfo\datas\maven_lib\com\ai\paas\cache-engine\2.0.1-SNAPSHOT\cache-engine-2.0.1-SNAPSHOT.jar;D:\asiainfo\datas\maven_lib\com\ai\paas\common-utils\2.0.1-SNAPSHOT\common-utils-2.0.1-SNAPSHOT.jar;D:\asiainfo\datas\maven_lib\redis\clients\jedis\2.9.0\jedis-2.9.0.jar;D:\asiainfo\datas\maven_lib\org\apache\commons\commons-pool2\2.4.3\commons-pool2-2.4.3.jar;D:\asiainfo\datas\maven_lib\org\springframework\boot\spring-boot-configuration-processor\1.5.10.RELEASE\spring-boot-configuration-processor-1.5.10.RELEASE.jar;D:\asiainfo\datas\maven_lib\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\asiainfo\datas\maven_lib\com\ai\woego\boot\sequence-spring-boot-autoconfigure\1.0.1-SNAPSHOT\sequence-spring-boot-autoconfigure-1.0.1-SNAPSHOT.jar;D:\asiainfo\datas\maven_lib\com\ai\paas\sequence-engine\2.0.1-SNAPSHOT\sequence-engine-2.0.1-SNAPSHOT.jar;D:\asiainfo\datas\maven_lib\org\apache\commons\commons-dbcp2\2.1.1\commons-dbcp2-2.1.1.jar;D:\asiainfo\datas\maven_lib\com\101tec\zkclient\0.10\zkclient-0.10.jar;D:\asiainfo\datas\maven_lib\org\apache\zookeeper\zookeeper\3.4.8\zookeeper-3.4.8.jar;D:\asiainfo\datas\maven_lib\log4j\log4j\1.2.16\log4j-1.2.16.jar;D:\asiainfo\datas\maven_lib\jline\jline\0.9.94\jline-0.9.94.jar;D:\asiainfo\datas\maven_lib\io\netty\netty\3.7.0.Final\netty-3.7.0.Final.jar;D:\asiainfo\datas\maven_lib\commons-httpclient\commons-httpclient\3.1\commons-httpclient-3.1.jar;D:\asiainfo\datas\maven_lib\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar;D:\asiainfo\datas\maven_lib\commons-codec\commons-codec\1.8\commons-codec-1.8.jar" com.ai.rai.group.system.MainTest
用escapeJava方法转义之后的字符串为:thi is a test \u8FD9\u662F\u4E00\u4E2A\u6D4B\u8BD5
用unescapeJava方法反转义之后的字符串为:thi is a test 这是一个测试
用escapeHtml方法转义之后的字符串为:thi is a test 这是一个测试
用unescapeHtml方法反转义之后的字符串为:thi is a test 这是一个测试
用escapeXml方法转义之后的字符串为:<?xml version="1.0" encoding="UTF-8"?>
<persons>
<person id="23">
<name>张 三</name>
<age>26</age>
</person>
<person id="22">
<name>李四</name>
<age>25</age>
</person>
</persons>
用unescapeXml方法反转义之后的字符串为:
张 三
26
李四
25
用escapeJavaScript方法转义之后的字符串为:thi is a test \u8FD9\u662F\u4E00\u4E2A\u6D4B\u8BD5
用unescapeJavaScript方法反转义之后的字符串为:thi is a test 这是一个测试
Process finished with exit code 0