怎么在Page<User>中替换list中的值

ts1001 发布于 2014/01/10 17:08
阅读 1K+
收藏 0

@JFinal 你好,想跟你请教个问题:

代码如下:
Page<User> users = User.dao.paginate(1, 10, "select *","from think_user");
renderJson(users);

结果如下:
{"pageSize":10,"pageNumber":1,"list":[{"id":10,"username":"1111","pingtai":null,"role_id":12,"last_login_time":0,"remark":"","status":"ON","last_location":null,"last_login_ip":null,"password":"6a3731e718c7f1c697b6680d6d6a95ab","all":null},{"id":12,"username":"bbb","pingtai":null,"role_id":12,"last_login_time":0,"remark":"","status":"ON","last_location":null,"last_login_ip":null,"password":"","all":null},{"id":15,"username":"admin","pingtai":null,"role_id":1,"last_login_time":0,"remark":"","status":"ON","last_location":null,"last_login_ip":null,"password":"6a3731e718c7f1c697b6680d6d6a95ab","all":null},{"id":1,"username":"guest","pingtai":null,"role_id":2,"last_login_time":0,"remark":"公共用户","status":"OFF","last_location":null,"last_login_ip":null,"password":"","all":null},{"id":0,"username":"aaa","pingtai":null,"role_id":0,"last_login_time":0,"remark":null,"status":"OFF","last_location":null,"last_login_ip":null,"password":"aaa","all":null}],"totalRow":5,"totalPage":1}
我想替换list中的值,例如:把
"username":"1111"
替换成
"username":"2222"

请指教!!!!!

加载中
1
华兹格
华兹格
Page 看看这个类的原理是什么,你自然知道为什么楼上都说让你用list循环了,Page就是List+一些分页统计信息值 
1
超级大富
超级大富
在renderJson之前,遍历users 的list,找到111这个对象,把值变了,把新的list赋值给新的users,再renderJson
超级大富
超级大富
回复 @ts1001 : new page ,把新的参数传进去就好了
t
ts1001
那我如何把list在赋给users呢??
0
sxgkwei
sxgkwei
只有自己去循环了哈。
t
ts1001
能给个代码吗?
0
t
ts1001

引用来自“sxgkwei”的答案

只有自己去循环了哈。
能给个代码吗?
0
程序员小贝
程序员小贝
循环做判断当某条记录 "username":"1111"时重新set "username":"2222"然后在封装page呗,我暂时想到的就是这种办法了,其余的好方法还没想到
0
RegnoiX
RegnoiX
.replace("\ "username\":\"1111\" ","\ "username\":\"2222\"")
0
铂金小鸟
铂金小鸟
users.getList()  拿出list 然后遍历
0
pantrick
pantrick
楼主你没说清,你要在rendjson之前还是之后更改,之前的话,只能按照楼上所言,之后的话,需要遍历js数组才能做到!
0
JFinal
JFinal
先  users.getList(),然后对这个 List 进行循环进行替换
t
ts1001
用你的方法搞定
JFinal
JFinal
回复 @ts1001 : 不用再将list赋给users,已经在里面了
t
ts1001
那我如何把list在赋给users呢?
返回顶部
顶部