首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JCodeModel中的嵌套注解

JCodeModel中的嵌套注解
EN

Stack Overflow用户
提问于 2018-08-25 14:59:56
回答 1查看 51关注 0票数 1

我想从XML文件创建一个CompoundIndexes注释,如下所示。

但是,我不知道如何将带参数的CompoundIndex注释放入CompoundIndexes注释中。这是我尝试过的方法。

代码语言:javascript
复制
JAnnotationUse indexesAnnotation = currentClass.annotate(CompoundIndexes.class);

JAnnotationArrayMember arrayMember = indexesAnnotation.paramArray("value");

 JAnnotationUse indexesParameter = currentClass.annotate(CompoundIndex.class)
.param("def", some_parameter);

arrayMember.param(indexesParameter);

然而,我最终得到了下面的结果。

我如何才能只获得嵌套的compoundIndexes部件,而摆脱下面的两个组件索引注释?

换句话说,如何创建一个批注并将其作为参数传递给另一个批注?

EN

回答 1

Stack Overflow用户

发布于 2018-11-26 05:44:55

从源头上看,param()似乎被贬低了,建议改用annotate()。使用annotate()可以解决您的问题:

代码语言:javascript
复制
JAnnotationUse indexesAnnotation = currentClass.annotate(CompoundIndexes.class);

JAnnotationArrayMember arrayMember = indexesAnnotation.paramArray("value");

arrayMember.annotate(CompoundIndex.class)
        .param("name", "email_age")
        .param("def", "{'email.id' : 1, 'age' : 1}");

提供:

代码语言:javascript
复制
@CompoundIndexes({
    @CompoundIndex(name = "email_age", def = "{'email.id' : 1, 'age' : 1}")
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52014825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档