mirror of
https://gitee.com/dromara/hutool.git
synced 2025-09-18 17:48:17 +08:00
fix code
This commit is contained in:
@@ -59,7 +59,7 @@ public abstract class ProxyFactory implements Serializable {
|
||||
* @return 代理对象
|
||||
*/
|
||||
public static <T> T createProxy(final T target, final Aspect aspect) {
|
||||
return create().proxy(target, aspect);
|
||||
return of().proxy(target, aspect);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +67,7 @@ public abstract class ProxyFactory implements Serializable {
|
||||
*
|
||||
* @return 代理工厂
|
||||
*/
|
||||
public static ProxyFactory create() {
|
||||
public static ProxyFactory of() {
|
||||
return ServiceLoaderUtil.loadFirstAvailable(ProxyFactory.class);
|
||||
}
|
||||
}
|
||||
|
@@ -105,7 +105,7 @@ public class CompressUtil {
|
||||
if (ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(archiverName)) {
|
||||
return new SevenZArchiver(file);
|
||||
}
|
||||
return StreamArchiver.create(charset, archiverName, file);
|
||||
return StreamArchiver.of(charset, archiverName, file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +128,7 @@ public class CompressUtil {
|
||||
if (ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(archiverName)) {
|
||||
return new SevenZArchiver(out);
|
||||
}
|
||||
return StreamArchiver.create(charset, archiverName, out);
|
||||
return StreamArchiver.of(charset, archiverName, out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -41,7 +41,7 @@ public class StreamArchiver implements Archiver {
|
||||
* @param file 归档输出的文件
|
||||
* @return StreamArchiver
|
||||
*/
|
||||
public static StreamArchiver create(final Charset charset, final String archiverName, final File file) {
|
||||
public static StreamArchiver of(final Charset charset, final String archiverName, final File file) {
|
||||
return new StreamArchiver(charset, archiverName, file);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class StreamArchiver implements Archiver {
|
||||
* @param out 归档输出的流
|
||||
* @return StreamArchiver
|
||||
*/
|
||||
public static StreamArchiver create(final Charset charset, final String archiverName, final OutputStream out) {
|
||||
public static StreamArchiver of(final Charset charset, final String archiverName, final OutputStream out) {
|
||||
return new StreamArchiver(charset, archiverName, out);
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ public class ExpressionFactory {
|
||||
* @return 单例的{@link ExpressionEngine}
|
||||
*/
|
||||
public static ExpressionEngine get(){
|
||||
return Singleton.get(ExpressionEngine.class.getName(), ExpressionFactory::create);
|
||||
return Singleton.get(ExpressionEngine.class.getName(), ExpressionFactory::of);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,7 +31,7 @@ public class ExpressionFactory {
|
||||
*
|
||||
* @return {@link ExpressionEngine}
|
||||
*/
|
||||
public static ExpressionEngine create() {
|
||||
public static ExpressionEngine of() {
|
||||
final ExpressionEngine engine = doCreate();
|
||||
StaticLog.debug("Use [{}] Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
|
||||
return engine;
|
||||
|
@@ -141,7 +141,7 @@ public class Ftp extends AbstractFtp {
|
||||
* @since 5.7.22
|
||||
*/
|
||||
public Ftp(final FTPClient client) {
|
||||
super(FtpConfig.create());
|
||||
super(FtpConfig.of());
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,7 @@ import java.nio.charset.Charset;
|
||||
public class FtpConfig implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static FtpConfig create() {
|
||||
public static FtpConfig of() {
|
||||
return new FtpConfig();
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ public class SimpleFtpServer {
|
||||
*
|
||||
* @return SimpleFtpServer
|
||||
*/
|
||||
public static SimpleFtpServer create() {
|
||||
public static SimpleFtpServer of() {
|
||||
return new SimpleFtpServer();
|
||||
}
|
||||
|
||||
|
@@ -91,7 +91,7 @@ public class Mail implements Builder<MimeMessage> {
|
||||
* @param mailAccount 邮件帐号
|
||||
* @return Mail
|
||||
*/
|
||||
public static Mail create(final MailAccount mailAccount) {
|
||||
public static Mail of(final MailAccount mailAccount) {
|
||||
return new Mail(mailAccount);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class Mail implements Builder<MimeMessage> {
|
||||
*
|
||||
* @return Mail
|
||||
*/
|
||||
public static Mail create() {
|
||||
public static Mail of() {
|
||||
return new Mail();
|
||||
}
|
||||
|
||||
|
@@ -388,7 +388,7 @@ public class MailUtil {
|
||||
*/
|
||||
private static String send(final MailAccount mailAccount, final boolean useGlobalSession, final Collection<String> tos, final Collection<String> ccs, final Collection<String> bccs, final String subject, final String content,
|
||||
final Map<String, InputStream> imageMap, final boolean isHtml, final File... files) {
|
||||
final Mail mail = Mail.create(mailAccount).setUseGlobalSession(useGlobalSession);
|
||||
final Mail mail = Mail.of(mailAccount).setUseGlobalSession(useGlobalSession);
|
||||
|
||||
// 可选抄送人
|
||||
if (CollUtil.isNotEmpty(ccs)) {
|
||||
|
@@ -21,7 +21,7 @@ public class PinyinFactory {
|
||||
* @return 单例的PinyinEngine
|
||||
*/
|
||||
public static PinyinEngine get(){
|
||||
return Singleton.get(PinyinEngine.class.getName(), PinyinFactory::create);
|
||||
return Singleton.get(PinyinEngine.class.getName(), PinyinFactory::of);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ public class PinyinFactory {
|
||||
*
|
||||
* @return {@link PinyinEngine}
|
||||
*/
|
||||
public static PinyinEngine create() {
|
||||
public static PinyinEngine of() {
|
||||
final PinyinEngine engine = doCreate();
|
||||
StaticLog.debug("Use [{}] Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
|
||||
return engine;
|
||||
|
@@ -50,7 +50,7 @@ public class QrConfig {
|
||||
* @return QrConfig
|
||||
* @since 4.1.14
|
||||
*/
|
||||
public static QrConfig create() {
|
||||
public static QrConfig of() {
|
||||
return new QrConfig();
|
||||
}
|
||||
|
||||
|
@@ -111,7 +111,7 @@ public class Sftp extends AbstractFtp {
|
||||
* @since 4.1.14
|
||||
*/
|
||||
public Sftp(final Session session, final Charset charset) {
|
||||
super(FtpConfig.create().setCharset(charset));
|
||||
super(FtpConfig.of().setCharset(charset));
|
||||
init(session, charset);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class Sftp extends AbstractFtp {
|
||||
* @param charset 编码
|
||||
*/
|
||||
public Sftp(final ChannelSftp channel, final Charset charset) {
|
||||
super(FtpConfig.create().setCharset(charset));
|
||||
super(FtpConfig.of().setCharset(charset));
|
||||
init(channel, charset);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class Sftp extends AbstractFtp {
|
||||
* @since 5.8.4
|
||||
*/
|
||||
public Sftp(final Session session, final Charset charset, final long timeOut) {
|
||||
super(FtpConfig.create().setCharset(charset).setConnectionTimeout(timeOut));
|
||||
super(FtpConfig.of().setCharset(charset).setConnectionTimeout(timeOut));
|
||||
init(session, charset);
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ public class Sftp extends AbstractFtp {
|
||||
* @since 5.8.4
|
||||
*/
|
||||
public Sftp(final ChannelSftp channel, final Charset charset, final long timeOut) {
|
||||
super(FtpConfig.create().setCharset(charset).setConnectionTimeout(timeOut));
|
||||
super(FtpConfig.of().setCharset(charset).setConnectionTimeout(timeOut));
|
||||
init(channel, charset);
|
||||
}
|
||||
// ---------------------------------------------------------------------------------------- Constructor end
|
||||
|
@@ -18,7 +18,7 @@ public class TemplateUtil {
|
||||
* @since 4.1.11
|
||||
*/
|
||||
public static TemplateEngine createEngine() {
|
||||
return TemplateFactory.create();
|
||||
return TemplateFactory.of();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,6 +29,6 @@ public class TemplateUtil {
|
||||
* @return {@link TemplateEngine}
|
||||
*/
|
||||
public static TemplateEngine createEngine(final TemplateConfig config) {
|
||||
return TemplateFactory.create(config);
|
||||
return TemplateFactory.of(config);
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ public class TemplateFactory {
|
||||
* @return 单例的TemplateEngine
|
||||
*/
|
||||
public static TemplateEngine get(){
|
||||
return Singleton.get(TemplateEngine.class.getName(), TemplateFactory::create);
|
||||
return Singleton.get(TemplateEngine.class.getName(), TemplateFactory::of);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,8 +33,8 @@ public class TemplateFactory {
|
||||
* @return {@link TemplateEngine}
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static TemplateEngine create() {
|
||||
return create(new TemplateConfig());
|
||||
public static TemplateEngine of() {
|
||||
return of(new TemplateConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ public class TemplateFactory {
|
||||
* @param config 模板配置,包括编码、模板文件path等信息
|
||||
* @return {@link TemplateEngine}
|
||||
*/
|
||||
public static TemplateEngine create(final TemplateConfig config) {
|
||||
public static TemplateEngine of(final TemplateConfig config) {
|
||||
final TemplateEngine engine = doCreate(config);
|
||||
StaticLog.debug("Use [{}] Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
|
||||
return engine;
|
||||
|
@@ -84,7 +84,7 @@ public class WitEngine implements TemplateEngine {
|
||||
Dict dict = null;
|
||||
|
||||
if (null != config) {
|
||||
dict = Dict.create();
|
||||
dict = Dict.of();
|
||||
// 自定义编码
|
||||
dict.set("DEFAULT_ENCODING", config.getCharset());
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import cn.hutool.extra.tokenizer.engine.TokenizerFactory;
|
||||
|
||||
/**
|
||||
* 分词工具类
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.3.3
|
||||
*/
|
||||
@@ -12,10 +12,10 @@ public class TokenizerUtil {
|
||||
|
||||
/**
|
||||
* 根据用户引入的分词引擎jar,自动创建对应的分词引擎对象
|
||||
*
|
||||
*
|
||||
* @return {@link TokenizerEngine}
|
||||
*/
|
||||
public static TokenizerEngine createEngine() {
|
||||
return TokenizerFactory.create();
|
||||
return TokenizerFactory.of();
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ public class TokenizerFactory {
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static TokenizerEngine get(){
|
||||
return Singleton.get(TokenizerEngine.class.getName(), TokenizerFactory::create);
|
||||
return Singleton.get(TokenizerEngine.class.getName(), TokenizerFactory::of);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,7 +31,7 @@ public class TokenizerFactory {
|
||||
*
|
||||
* @return {@link TokenizerEngine}
|
||||
*/
|
||||
public static TokenizerEngine create() {
|
||||
public static TokenizerEngine of() {
|
||||
final TokenizerEngine engine = doCreate();
|
||||
StaticLog.debug("Use [{}] Tokenizer Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
|
||||
return engine;
|
||||
|
@@ -16,7 +16,7 @@ public class ArchiverTest {
|
||||
@Ignore
|
||||
public void zipTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.zip");
|
||||
StreamArchiver.create(CharsetUtil.UTF_8, ArchiveStreamFactory.ZIP, file)
|
||||
StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.ZIP, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
@@ -28,7 +28,7 @@ public class ArchiverTest {
|
||||
@Ignore
|
||||
public void tarTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.tar");
|
||||
StreamArchiver.create(CharsetUtil.UTF_8, ArchiveStreamFactory.TAR, file)
|
||||
StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.TAR, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
@@ -40,7 +40,7 @@ public class ArchiverTest {
|
||||
@Ignore
|
||||
public void cpioTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.cpio");
|
||||
StreamArchiver.create(CharsetUtil.UTF_8, ArchiveStreamFactory.CPIO, file)
|
||||
StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.CPIO, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
|
@@ -21,17 +21,17 @@ public class AviatorTest {
|
||||
final ExpressionEngine engine = new AviatorEngine();
|
||||
String exp =
|
||||
"\"[foo i=\"+ foo.i + \", f=\" + foo.f + \", date.year=\" + (foo.date.year+1900) + \", date.month=\" + foo.date.month + \", bars[0].name=\" + #foo.bars[0].name + \"]\"";
|
||||
String result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
String result = (String) engine.eval(exp, Dict.of().set("foo", foo));
|
||||
Assert.assertEquals("[foo i=100, f=3.14, date.year=2020, date.month=10, bars[0].name=bar]", result);
|
||||
|
||||
// Assignment.
|
||||
exp = "#foo.bars[0].name='hello aviator' ; #foo.bars[0].name";
|
||||
result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
result = (String) engine.eval(exp, Dict.of().set("foo", foo));
|
||||
Assert.assertEquals("hello aviator", result);
|
||||
Assert.assertEquals("hello aviator", foo.bars[0].getName());
|
||||
|
||||
exp = "foo.bars[0] = nil ; foo.bars[0]";
|
||||
result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
result = (String) engine.eval(exp, Dict.of().set("foo", foo));
|
||||
Console.log("Execute expression: " + exp);
|
||||
Assert.assertNull(result);
|
||||
Assert.assertNull(foo.bars[0]);
|
||||
|
@@ -16,7 +16,7 @@ public class ExpressionUtilTest {
|
||||
|
||||
@Test
|
||||
public void evalTest(){
|
||||
final Dict dict = Dict.create()
|
||||
final Dict dict = Dict.of()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
@@ -28,7 +28,7 @@ public class ExpressionUtilTest {
|
||||
public void jexlTest(){
|
||||
final ExpressionEngine engine = new JexlEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
final Dict dict = Dict.of()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
@@ -51,7 +51,7 @@ public class ExpressionUtilTest {
|
||||
public void mvelTest(){
|
||||
final ExpressionEngine engine = new MvelEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
final Dict dict = Dict.of()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
@@ -63,7 +63,7 @@ public class ExpressionUtilTest {
|
||||
public void jfireELTest(){
|
||||
final ExpressionEngine engine = new JfireELEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
final Dict dict = Dict.of()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
@@ -75,7 +75,7 @@ public class ExpressionUtilTest {
|
||||
public void spELTest(){
|
||||
final ExpressionEngine engine = new SpELEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
final Dict dict = Dict.of()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
@@ -87,7 +87,7 @@ public class ExpressionUtilTest {
|
||||
public void rhinoTest(){
|
||||
final ExpressionEngine engine = new RhinoEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
final Dict dict = Dict.of()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
|
@@ -4,7 +4,7 @@ public class SimpleFtpServerTest {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
SimpleFtpServer
|
||||
.create()
|
||||
.of()
|
||||
.addAnonymous("d:/test/ftp/")
|
||||
.start();
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ public class MailAccountTest {
|
||||
mailAccount.setAuth(true);
|
||||
mailAccount.setSslEnable(true);
|
||||
|
||||
final Mail mail = Mail.create(mailAccount)
|
||||
final Mail mail = Mail.of(mailAccount)
|
||||
.setTos("xx@xx.com")
|
||||
.setTitle("邮箱验证")
|
||||
.setContent("您的验证码是:<h3>2333</h3>")
|
||||
|
@@ -47,7 +47,7 @@ public class QrCodeUtilTest {
|
||||
final String targetPath = FileUtil.isWindows() ? "d:/test/qrcodeWithLogo.jpg" : "~/Desktop/hutool/qrcodeWithLogo.jpg";
|
||||
QrCodeUtil.generate(//
|
||||
"https://hutool.cn/", //
|
||||
QrConfig.create().setImg(icon), //
|
||||
QrConfig.of().setImg(icon), //
|
||||
FileUtil.touch(targetPath));
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class QrCodeUtilTest {
|
||||
|
||||
@Test
|
||||
public void pdf417Test(){
|
||||
final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.PDF_417, QrConfig.create());
|
||||
final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.PDF_417, QrConfig.of());
|
||||
Assert.assertNotNull(image);
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@ public class JetbrickTest {
|
||||
.setCustomEngine(JetbrickEngine.class);
|
||||
final TemplateEngine engine = TemplateUtil.createEngine(config);
|
||||
final Template template = engine.getTemplate("jetbrick_test.jetx");
|
||||
final String result = template.render(Dict.create().set("name", "hutool"));
|
||||
final String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", StrUtil.trim(result));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class JetbrickTest {
|
||||
.setCustomEngine(JetbrickEngine.class);
|
||||
final TemplateEngine engine = TemplateUtil.createEngine(config);
|
||||
final Template template = engine.getTemplate("hello,${name}");
|
||||
final String result = template.render(Dict.create().set("name", "hutool"));
|
||||
final String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", StrUtil.trim(result));
|
||||
}
|
||||
}
|
||||
|
@@ -31,13 +31,13 @@ public class TemplateUtilTest {
|
||||
// 字符串模板, 默认模板引擎,此处为Beetl
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig());
|
||||
final Template template = engine.getTemplate("hello,${name}");
|
||||
final String result = template.render(Dict.create().set("name", "hutool"));
|
||||
final String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
engine = TemplateUtil.createEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||
final Template template2 = engine.getTemplate("beetl_test.btl");
|
||||
final String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
final String result2 = template2.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ public class TemplateUtilTest {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = new BeetlEngine(new TemplateConfig("templates"));
|
||||
final Template template = engine.getTemplate("hello,${name}");
|
||||
final String result = template.render(Dict.create().set("name", "hutool"));
|
||||
final String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
engine = new BeetlEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||
final Template template2 = engine.getTemplate("beetl_test.btl");
|
||||
final String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
final String result2 = template2.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@@ -62,12 +62,12 @@ public class TemplateUtilTest {
|
||||
final TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(RythmEngine.class));
|
||||
final Template template = engine.getTemplate("hello,@name");
|
||||
final String result = template.render(Dict.create().set("name", "hutool"));
|
||||
final String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
final Template template2 = engine.getTemplate("rythm_test.tmpl");
|
||||
final String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
final String result2 = template2.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ public class TemplateUtilTest {
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.STRING).setCustomEngine(FreemarkerEngine.class));
|
||||
Template template = engine.getTemplate("hello,${name}");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(FreemarkerEngine.class));
|
||||
template = engine.getTemplate("freemarker_test.ftl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
}
|
||||
|
||||
@@ -94,18 +94,18 @@ public class TemplateUtilTest {
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.STRING).setCustomEngine(VelocityEngine.class));
|
||||
Template template = engine.getTemplate("你好,$name");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(VelocityEngine.class));
|
||||
template = engine.getTemplate("velocity_test.vtl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
|
||||
template = engine.getTemplate("templates/velocity_test.vtl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
}
|
||||
|
||||
@@ -115,14 +115,14 @@ public class TemplateUtilTest {
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(EnjoyEngine.class));
|
||||
Template template = engine.getTemplate("#(x + 123)");
|
||||
String result = template.render(Dict.create().set("x", 1));
|
||||
String result = template.render(Dict.of().set("x", 1));
|
||||
Assert.assertEquals("124", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = new EnjoyEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(EnjoyEngine.class));
|
||||
template = engine.getTemplate("enjoy_test.etl");
|
||||
result = template.render(Dict.create().set("x", 1));
|
||||
result = template.render(Dict.of().set("x", 1));
|
||||
Assert.assertEquals("124", result);
|
||||
}
|
||||
|
||||
@@ -132,14 +132,14 @@ public class TemplateUtilTest {
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(ThymeleafEngine.class));
|
||||
Template template = engine.getTemplate("<h3 th:text=\"${message}\"></h3>");
|
||||
String result = template.render(Dict.create().set("message", "Hutool"));
|
||||
String result = template.render(Dict.of().set("message", "Hutool"));
|
||||
Assert.assertEquals("<h3>Hutool</h3>", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(ThymeleafEngine.class));
|
||||
template = engine.getTemplate("thymeleaf_test.ttl");
|
||||
result = template.render(Dict.create().set("message", "Hutool"));
|
||||
result = template.render(Dict.of().set("message", "Hutool"));
|
||||
Assert.assertEquals("<h3>Hutool</h3>", result);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class TemplateUtilTest {
|
||||
.setCustomEngine(WitEngine.class);
|
||||
TemplateEngine engine = TemplateUtil.createEngine(config);
|
||||
Template template = engine.getTemplate("/wit_test.wit");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", StrUtil.trim(result));
|
||||
|
||||
// 字符串模板
|
||||
@@ -170,7 +170,7 @@ public class TemplateUtilTest {
|
||||
.setCustomEngine(WitEngine.class);
|
||||
engine = TemplateUtil.createEngine(config);
|
||||
template = engine.getTemplate("<%var name;%>hello,${name}");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", StrUtil.trim(result));
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ public class ThymeleafTest {
|
||||
// 字符串模板
|
||||
final TemplateEngine engine = new ThymeleafEngine(new TemplateConfig());
|
||||
final Template template = engine.getTemplate("<h3 th:each=\"item : ${list}\" th:text=\"${item.name}\"></h3>");
|
||||
final String render = template.render(Dict.create().set("list", list));
|
||||
final String render = template.render(Dict.of().set("list", list));
|
||||
Assert.assertEquals("<h3>a</h3><h3>b</h3><h3>2019-01-01 00:00:00</h3>", render);
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@ public class VelocityTest {
|
||||
config.setCharset(CharsetUtil.GBK);
|
||||
final TemplateEngine engine = TemplateUtil.createEngine(config);
|
||||
final Template template = engine.getTemplate("velocity_test_gbk.vtl");
|
||||
final String result = template.render(Dict.create().set("name", "hutool"));
|
||||
final String result = template.render(Dict.of().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user