我想以速度
访问对象属性我有以下内容。
public class myObject(){
@key("name")
private String name;
@key("other")
private String other;
/*
getters and setters here
*/
}
然后我有另一个包含myObject对象列表的类
public class testClass(){
@key("objectList")
private List<myObject> randomlist;
}
如何访问myObject列表的name
和other
?
我的速度看起来如下,但不起作用
#macro( getListContent $tag $tag2 $listName)
#foreach($object in [0..$listName-size])
<$tag1>$object-name</$tag1>
<$tag2>$object-other</$tag2>
#end
#end
最后我有
#getListContent("name" "other" $testClass.get("objectList"))
但这不起作用。如何访问使用注释@key
映射的对象属性。某些帮助非常有用。
答案 0 :(得分:0)
您应该看到macro文档,在您的foreach语句中,您需要放置列表对象,
此外,名称和其他名称都是私人的,因此无法访问,
但你可以使用public
getters方法:
#macro( getListContent $tag $tag2 $listName)
#foreach($object in $listName)
<$tag1>$object.getName()</$tag1>
<$tag2>$object.getOther()</$tag2>
#end
#end