gpt4 book ai didi

java - 无法在jsp页面中获取正确的注释名称

转载 作者:行者123 更新时间:2023-12-01 12:20:34 25 4
gpt4 key购买 nike

在下面的代码中,第一个循环迭代给定类的字段(由 spring Controller 传递给 View ),第二个循环迭代每个字段的注释:

<x:Form>
<c:forEach var="item" items="${command['class'].declaredFields}" varStatus="status">
<c:forEach var="item2" items="${item.declaredAnnotations}">
<c:choose>
<c:when test="${item2['class'].simpleName == 'Checkbox'}">
<x:Checkbox/>
</c:when>
<c:when test="${item2['class'].simpleName == 'DataList'}">
<x:DataList/>
</c:when>
<c:when test="${item2['class'].simpleName == 'Input'}">
<x:Input/>
</c:when>
<c:when test="${item2['class'].simpleName == 'Radiobutton'}">
<x:Radiobutton/>
</c:when>
<c:when test="${item2['class'].simpleName == 'Select'}">
<x:Select/>
</c:when>
<c:when test="${item2['class'].simpleName == 'Textarea'}">
<x:Textarea/>
</c:when>
</c:choose>
</c:forEach>
</c:forEach>

<button type="submit" class="btn btn-default">Enviar</button>
</x:Form>

我的问题是我无法获取注释的真实姓名。 item2[class].simpleName 的结果类似于 $Proxy55 (数字有所不同)。

有人知道如何获取注释的真实姓名吗?

最佳答案

您正在使用java.lang.annotation.Annotation。当您在 Annotation 上调用 getClass() 时,您将获得一个代理。您需要改为调用 annotationType()

item2[class].simpleName 更改为 item2.annotationType().simpleName

关于java - 无法在jsp页面中获取正确的注释名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26692286/

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