使用gradle+freemarker生成代码报错The following has evaluated to null or missing
* What went wrong:
Execution failed for task ':generate'.
> freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> primaryKeys[0] [in template "src/src/main/java/${root.javaPackagePath}/${moduleName}/mgt/controller/${entityName}Controller.java.ftl" a
t line 169, column 60]
----
Tip: It's the final [] step that caused this error, not those before it.
----
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value li
ke myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expressi
on; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${primaryKeys[0].name} [in template "src/src/main/java/${root.javaPackagePath}/${moduleName}/mgt/controller/${entityName
}Controller.java.ftl" at line 169, column 58]
----
================================================================
primaryKeys的获取代码
def primaryKeys = metadata.getPrimaryKeys(null, schema, tableName)
169行报错代码
public ${entityName}Response view(@PathVariable("${primaryKeys[0].name}") final ${primaryKeys[0].type} ${primaryKeys[0].name}, Locale locale) {
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
${(primaryKeys[ 0 ].name)!}这种写法相比较 ${primaryKeys[ 0 ].name}来说是不是当传值为空时,不报错了,测试有用的,就是不明白原理,大佬厉害,真的很强!!
非常感谢,这个真的帮了我很大的忙了,由于工作比较忙,忘了感谢您了。非常感谢您,太厉害 了!
请使用 ${(primaryKeys[ 0 ].name)!}
请使用 ${(primaryKeys[0].name)!}