diff --git a/src/main/java/com/jfinal/template/source/StringSource.java b/src/main/java/com/jfinal/template/source/StringSource.java index 4c0938fcf2cf7320c9ca54d506fdbf5714866379..62df37ed8cebb004901e704d889a553adf9423df 100644 --- a/src/main/java/com/jfinal/template/source/StringSource.java +++ b/src/main/java/com/jfinal/template/source/StringSource.java @@ -40,7 +40,15 @@ public class StringSource implements ISource { this.content = new StringBuilder(content); this.cacheKey = cache ? HashKit.md5(content) : null; // 不缓存只要将 cacheKey 值赋为 null 即可 } - + + public StringSource(String content, String cacheKey) { + if (StrKit.isBlank(content)) { + throw new IllegalArgumentException("content can not be blank"); + } + this.content = new StringBuilder(content); + this.cacheKey = cacheKey; // 不缓存只要将 cacheKey 值赋为 null 即可 + } + public StringSource(StringBuilder content, boolean cache) { if (content == null || content.length() == 0) { throw new IllegalArgumentException("content can not be blank"); @@ -48,6 +56,14 @@ public class StringSource implements ISource { this.content = content; this.cacheKey = cache ? HashKit.md5(content.toString()) : null; // 不缓存只要将 cacheKey 值赋为 null 即可 } + + public StringSource(StringBuilder content, String cacheKey) { + if (content == null || content.length() == 0) { + throw new IllegalArgumentException("content can not be blank"); + } + this.content = content; + this.cacheKey = cacheKey; // 不缓存只要将 cacheKey 值赋为 null 即可 + } public boolean isModified() { return false;