开发者社区> 问答> 正文

使用gradle+freemarker生成代码报错The following h?400报错

* 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) {

展开
收起
爱吃鱼的程序员 2020-06-08 13:15:13 576 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    请使用${(primaryKeys[0].name)!}请使用${(primaryKeys[0].name)!}非常感谢,这个真的帮了我很大的忙了,由于工作比较忙,忘了感谢您了。非常感谢您,太厉害了!

     ${(primaryKeys[0].name)!}这种写法相比较 ${primaryKeys[0].name}来说是不是当传值为空时,不报错了,测试有用的,就是不明白原理,大佬厉害,真的很强!!

    2020-06-08 13:15:23
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载