1. 新建一个Java实体类
@Entity @Table(name = "MARKET_LADDER_PRICE_INTERVAL") @AttributeOverride(column = @Column(name = "INTERVAL_ID"), name = "id") public class LadderPriceInterval extends IdEntity { private static final long serialVersionUID = 1L; private Integer beginNum; // 开始区间 private Integer endNum; // 结束区间 private String framId; // 框架协议ID @Column(name = "BEGIN_NUM") public Integer getBeginNum() { return beginNum; } public void setBeginNum(Integer beginNum) { this.beginNum = beginNum; } @Column(name = "END_NUM") public Integer getEndNum() { return endNum; } public void setEndNum(Integer endNum) { this.endNum = endNum; } @Column(name = "FRAM_ID") public void setFramId(String framId) { this.framId = framId; } public void setSortNum(Integer sortNum) { this.sortNum = sortNum; } }
2. 生成JSON字符串
/** * 根据框架协议ID 获取商品阶梯价格 */ @RequestMapping(value = "/getLadListByFrameId") @ResponseBody public String getLadListByFrameId(String framId) { List<LadderPriceInterval> ladList=ladderPriceIntervalService.queryByFramId(framId); return JSONArray.fromObject(ladList).toString(); }
3. js解析JSON字符串
$.ajax({ type : "post", data : {"framId":framId}, url : "/unionpay/scmarket/productController/getLadListByFrameId", async : false, success : function(data) { var ladJson = new Array(); ladJson = eval("("+data+")"); if(ladJson!=null&&ladJson.length>=0){ for(var i in ladJson){ var beginNum=ladJson[i].beginNum; var endNum=ladJson[i].endNum; //你自己操作 } } } });
时间: 2024-11-09 00:04:50