ALiBABa fastjson json传前台 toString,fastjsonjson
ALiBABa fastjson json传前台 toString,fastjsonjson
Mapper代码
public class GoodsInfo implements Serializable {
private static final long serialVersionUID = 1L;
private String gid; //商品ID
private String gname;//商品名称
private String gcid;//商品类别
private String gunit;//单位
private float gpin;//进价
private float gpout;//售价
private int gamount;//库存
public String getGid() {
return gid;
}
public String getGname() {
return gname;
}
public String getGcid() {
return gcid;
}
public String getGunit() {
return gunit;
}
public float getGpin() {
return gpin;
}
public float getGpout() {
return gpout;
}
public int getGamount() {
return gamount;
}
public GoodsInfo(String gid, String gname, String gcid, String gunit,
float gpin, float gpout, int gamount) {
super();
this.gid = gid;
this.gname = gname;
this.gcid = gcid;
this.gunit = gunit;
this.gpin = gpin;
this.gpout = gpout;
this.gamount = gamount;
}
//构造方法
public GoodsInfo() {
super();
}
public String toString(){
StringBuffer sb = new StringBuffer();
sb.append("{");
sb.append("\"gid\":\""+gid+"\",");
sb.append("\"gname\":\""+gname+"\",");
sb.append("\"gcid\":\""+gcid+"\",");
sb.append("\"gunit\":\""+gunit+"\",");
sb.append("\"gpin\":\""+gpin+"\",");
sb.append("\"gpout\":\""+gpout+"\",");
sb.append("\"gamount\":\""+gamount+"\"");
sb.append("}");
return sb.toString();
}
public static void main(String[] args) {
System.out.println(new GoodsInfo("1","2","2","2",2.0f,2.0f,2).toString());
}
}
Controller
@RequestMapping(“editGood”)
@ResponseBody
public String editGood(HttpServletResponse response,HttpServletRequest request)
{
String gid = request.getParameter(“gid”);
GoodsInfo goodsInfo = goodsInfoService.findGoodsById(gid);
JSONObject result = JSONObject.parseObject(goodsInfo.toString());
String data = result.toJSONString();
System.out.println(data);
return data;
}
前台
//编辑方法
function edit(index,gid)
{
alert(index+"进入修改方法"+gid);
$('#divSelect').panel('open');
document.getElementById("divLinkBtn").style.display = "block";
$.ajax({
type:"POST",
url:'${ctx}/goodinfo/editGood?gid='+gid,
success:function(msg){
var data = $.parseJSON(msg);
alert(data.gid);
}
});
}
相关文章
- 暂无相关文章
用户点评