jspではajaxで複雑なパラメータを送信しnew object()で組み立てて送信し,受け入れる

2371 ワード

ajaxでリクエストを送信する場合、次のjavaが受け入れるパラメータの複雑なパラメータがあります.
	private List piclist;
    private List objanswerList;
    private Long homeworkid;

最初のステップjsを組み立てるps:piclistとobjanswerListは配列です
var submitParam = new Object();
 submitParam.piclist = piclist;
 submitParam.objanswerList = objanswerList;
 submitParam.homeworkid = '';

ステップ2 ajaxリクエストの送信ポイント:submitParam:JSON.stringify(submitParam)
$.ajax({
   type:"post",
      url:"url",
      data:{
          submitParam: JSON.stringify(submitParam)
      },
      dataType:"json",
      async:false,
      // headers:{"Content-Type":"application/json"},
      success:function(data){
          if(data.status=="1"){
             
      }
  });

ステップ3バックグラウンド受入1>受入パラメータを定義したbean
public class SubmitParam {
    private List piclist;
    private List objanswerList;
    private Long homeworkid;

    public List getPiclist() {
        return piclist;
    }

    public void setPiclist(List piclist) {
        this.piclist = piclist;
    }

    public List getObjanswerList() {
        return objanswerList;
    }

    public void setObjanswerList(List objanswerList) {
        this.objanswerList = objanswerList;
    }

    public Long getHomeworkid() {
        return homeworkid;
    }

    public void setHomeworkid(Long homeworkid) {
        this.homeworkid = homeworkid;
    }

    @Override
    public String toString() {
        return "SubmitParam{" +
                "piclist=" + piclist +
                ", objanswerList=" + objanswerList +
                ", homeworkid=" + homeworkid +
                '}';
    }
}

2>String submitParamStr=request.getParameter(「submitParam」)を使用します.パラメータを受け入れる
 String submitParamStr = request.getParameter("submitParam");
 if(submitParamStr!=null&&!"".equals(submitParamStr)){
   SubmitParam submitParam = JsonConvert.parseObject(submitParamStr, SubmitParam.class);
 }

そしてsubmitParamというパラメータオブジェクトを使うことができます
いいね