jquery ajax 取多行数据库记录,在jsp页面遍历。使用Gson。

[b]1、action代码[/b]

@SuppressWarnings("unchecked")
public String getChargeMode(){
//根据产品id 获取计费方式
String productid ="402881833492ec97013492f512870003";
List<ChargeMode> vmchargeList = chargeModeService.findByProductId(productid);

//New个 Gson对象
Gson gson = new Gson();
//直接toJson 真是Gson的强大之处
String result = gson.toJson(vmchargeList);

System.out.println(result);
//基类定义的 返回形式
return ajaxText(result);

}


[b]2、hibernate实体[/b]

private String id;
//transient这个关键字是过滤不必要的底层信息
transient
private Product product;
private String chargeName;
private String timeType;
private String unit;


[b]3、jsp页面[/b]

jQuery.ajax({
dataType: "json",
type: "post",
url: "<%=basePath%>product!getChargeMode.action",

success: function(data) { jQuery.each(data, function(i, field){
//遍历所有记录, alert所有的id
alert(field['id']);
});

}

});



[b]4、action输出[/b]
//能以此格式 存储多行记录

[{"id":"40288036379bd5b101379bd6455e0001","chargeName":"包月","timeType":"M","unit":"元/月"}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值