[b]1、action代码[/b]
[b]2、hibernate实体[/b]
[b]3、jsp页面[/b]
[b]4、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":"元/月"}