如何在另一个对象中添加对象的字段以将其显示在jsp中
获取另一个对象 UserActivity
来获取 UserList
List<User> UserList=usersService.findUsers();
我通过迭代此列表并基于 id
Iterator<User> iterator = UserList.iterator();
while(iterator.hasNext()){
User user= iterator.next() ;
System.out.println("userA"+user.getId());
UserActivity userActivity = userActivityService.findUser(user.getId());
System.out.println("userActivity"+userActivity.getLastSeen_time());
}
,并且想要 UserActivity 对象的字段 LastSeen_time。现在我想将 User 和 UserActivity.LastSeen_time 传递到一个 jsp 页面,我将在其中将其显示为
User.name User.id UserActivity.LastSeen_Time(corresponding time for each id)
How can i do it, Please suggest
I am getting a UserList by following
List<User> UserList=usersService.findUsers();
than am iterating over this list and based on id
getting another object UserActivity
, and want UserActivity object's field LastSeen_time.
Iterator<User> iterator = UserList.iterator();
while(iterator.hasNext()){
User user= iterator.next() ;
System.out.println("userA"+user.getId());
UserActivity userActivity = userActivityService.findUser(user.getId());
System.out.println("userActivity"+userActivity.getLastSeen_time());
}
Now i want to pass User and UserActivity.LastSeen_time to a jsp page, where i will display it as
User.name User.id UserActivity.LastSeen_Time(corresponding time for each id)
How can i do it, Please suggest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将必要的信息放入请求范围即可。对于用户活动,最简单的方法是使用
MapuserActivities
以用户 ID 作为键。然后,您可以使用${userActivities[user.id]}
在 EL 中访问它。例如
,然后在 JSP 中
(我假设
getLastSeen()
返回一个Date
)Just put the necessary information in the request scope. For user activities, easiest is to have a
Map<Long, UserActivity> userActivities
with user ID as key. You can then access it in EL using${userActivities[user.id]}
.E.g.
and then in JSP
(I'm assuming that
getLastSeen()
returns aDate
)