gpt4 book ai didi

java - 限制 FreeMarker 中的字符串长度

转载 作者:技术小花猫 更新时间:2023-10-29 12:45:56 26 4
gpt4 key购买 nike

我正在尝试从 FreeMarker 中的字符串中获取子字符串。然而,有两个问题需要考虑:

  1. 字符串可以为空
  2. 字符串可以小于最大字符串长度

我做了以下事情:

<#list landingpage1.popularItems as row>
<li>
<span class="minititle">
<#assign minititle=(row.title!"")>
<#if minititle?length &lt; 27>
${minititle}
<#else>
${minititle?substring(0,26)} ...
<#/if>
</span>
</li>
</#list>

我收到一个 freemarker 错误提示:

Failed to load templates: Encountered "</#list>" at line 144, column 65 in landingpage1.ftl.
Was expecting one of:
<ATTEMPT> ...
<IF> ...
<LIST> ...
<FOREACH> ...
<SWITCH> ...
<ASSIGN> ...
<GLOBALASSIGN> ...
<LOCALASSIGN> ...
<INCLUDE> ...
<IMPORT> ...
<FUNCTION> ...
<MACRO> ...
<TRANSFORM> ...
<VISIT> ...
<STOP> ...
<RETURN> ...
<CALL> ...
<SETTING> ...
<COMPRESS> ...
<COMMENT> ...
<TERSE_COMMENT> ...
<NOPARSE> ...
<END_IF> ...
<BREAK> ...
<SIMPLE_RETURN> ...
<HALT> ...
<FLUSH> ...
<TRIM> ...
<LTRIM> ...
<RTRIM> ...
<NOTRIM> ...
<SIMPLE_NESTED> ...
<NESTED> ...
<SIMPLE_RECURSE> ...
<RECURSE> ...
<FALLBACK> ...
<ESCAPE> ...
<NOESCAPE> ...
<UNIFIED_CALL> ...
<WHITESPACE> ...
<PRINTABLE_CHARS> ...
<FALSE_ALERT> ...
"${" ...
"#{" ...

很奇怪。有人可以帮忙吗?

最佳答案

经过大量测试后,错误神奇地自行解决了。一定是业力。

我最后的安全检查代码:

<#assign minititle=(row.title!"")>
<#if minititle?length &lt; 27>
${minititle}
<#else>
${minititle?substring(0,26)} ...
</#if>

希望对其他人有帮助

关于java - 限制 FreeMarker 中的字符串长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3394917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com