在 EL 中打印所有 bean 属性,无需每次都重写 toString()
我在 EL 中有一个 Bean 列表/地图,或者至少我认为是这样,而且我厌倦了花几个小时试图弄清楚哪些部分属于彼此。所以我像 ${example}
一样简单地打印它。
football.beans.FootballFixture@72bec69[match=football.domain.FootballMatch@773aa1d5[id=360496,比赛=PREMIERSHIP,seasonId=2011,groupName=,roundType=,roundNumber=,matchPeriod=FULL_TIME,matchDay=3,场地 ID=33,场地=白鹿巷,venueCity=伦敦,homeTeamId=t6,awayTeamId=t43,homeScore=1,awayScore=5,scorers=[football.domain.Score@3d5bed54[567825,AWAY,2011-08-28 14:05:05.0,34,哲科,FIRST_HALF 进球
目前我正在压倒一切每次都在我的 bean 上使用 toString()
。如果 JSP 中有类似 PHP 的 print_r
的东西那就太好了。任何人都知道如何停止我因这个问题引起的永恒头痛。
I have a list/map of beans in EL, or at least I assume it is and I'm fed up with spending hours going through trying to work out which sections belong to each other. So I print it plain like ${example}
.
football.beans.FootballFixture@72bec69[match=football.domain.FootballMatch@773aa1d5[id=360496,competition=PREMIERSHIP,seasonId=2011,groupName=,roundType=,roundNumber=,matchPeriod=FULL_TIME,matchDay=3,venueId=33,venue=White Hart Lane,venueCity=London,homeTeamId=t6,awayTeamId=t43,homeScore=1,awayScore=5,scorers=[football.domain.Score@3d5bed54[567825,AWAY,2011-08-28 14:05:05.0,34,GOAL,Dzeko,,FIRST_HALF
Currently I am overriding toString()
on my beans every time. It'd be great to have something similar to PHP's print_r
in JSP. Anybody know how to stop my eternal headache caused by this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
导入 Jackson JSON 库并执行类似的操作(假设“myList”是您已经定义的列表/映射):
这会将完整的列表对象作为字符串打印到标准输出。
希望这有帮助。
Import the Jackson JSON library and do something like this (assuming "myList" is the list/map you already have defined):
This would print out your complete list object as a string to standard out.
Hope this helps.
您可以使用 Pojomatic 库。
如果您使用maven,请将依赖项添加到
pom.xml
。然后将
@AutoProperty
注释添加到您想要读取的类,例如PostVo.java
。并且,像这样重写 toString 方法:
您可以重写
hashCode()
和equals(Object obj)
。You can use Pojomatic lib.
If you use maven, add dependency to
pom.xml
.Then add
@AutoProperty
annotation to class you want to read likePostVo.java
.And, override toString method like this:
You can override
hashCode()
andequals(Object obj)
.