錯誤 The request sent by the client was syntactically incorrect.

  今天在作ajax向springmvc發送request請求的時候爆出了這樣的一個錯誤:The request sent by the client was syntactically incorrect.頁面顯示的是400java

ajax代碼:ajax

 1  $('#sub').on('click', function()
 2           {
 3              var realname,phnum,age,sex,qqnumber,wechartnumber,address
 4              realname = $("#realname").val(); 
 5              phnum = $("#phonenumber").val();
 6              age =$("#age").val();
 7              qqnumber =$("#qqnumber").val();
 8              wechartnumber = $("#wechart").val();
 9              address =$("#address").val();
10              sex=$("input[name='sex']:checked").val();
11                  var doctorInfo=
12                      {
13                             "realname":realname,
14                             "phnum" : phnum,
15                             "age" : age,
16                             "sex" : sex,
17                             "qqnumber" : qqnumber,
18                              "wechartnumber" :wechartnumber,
19                              "address" : address,
20                      };
21             if (realname.length > 2 && phnum.length == 11 && age.length > 0 && sex.length > 0
22                 && qqnumber.length > 0 && wechartnumber.length > 0 && address.length > 0)
23                  {
24                     $.ajax
25                     ({
26                         dataType: "json",
27                         contentType: "application/json; charset=utf-8",   
28                         type : "POST",
29                         url : "UserAddJbm",
30                         data :
31                         JSON.stringify (doctorInfo),
32                         async : false,
33                         error : function(XMLHttpRequest, textStatus, errorThrown)
34                          {
35                             layer.msg("網路問題,正在修復中......" );
36                         },
37                     success : function(mark) 
38                     {
39                             layer.msg(mark.doctoradd);
40                             if(mark.doctoradd=="基本信息錄入成功")
41                             {
42                                 $('.layui-btn').removeAttr("disabled");
43                                 $('.layui-btn').removeClass("layui-btn-disabled");
44                                 $('.layui-btn').addClass("layui-btn-normal");
45                             }
46                     }
47                  });
48             }
49          });

SpringMVC代碼spring

// 用戶信息註冊
    @RequestMapping(value = "/UserAddJbm", method = RequestMethod.POST)
    @ResponseBody
    private Map<String, String>  UserRegisterJb(@RequestBody DoctorInfo doctorInfo)
    {
        System.out.println(doctorInfo.toString());
        Map<String, String> map=new HashMap<String, String>();
        PhoneLogin login = (PhoneLogin) session.getAttribute(Constant.REGISTER_PHONELOGIN);
        if (login != null)
        {
            Integer docid = register.DcotorRegister(login, doctorInfo);
            if (docid != null)
            {
                    // 將用戶的信息直接寫到session中去
                    session.setAttribute(Constant.SESSION_DOC, doctorInfo);
                    // 提示信息寫到map中
                    map.put(Constant.DOC_ADD, Constant.DOC__ADD_SUCC) ;
            }
            else
            {
                // 註冊失敗可是有session的狀況下
                    map.put(Constant.DOC_ADD, Constant.DOC__ADD_FAIL) ;
            }
        }
        else
        {
            // session中沒有數據,提示用戶沒有登陸,返回到登陸頁面
            map.put(Constant.DOC_ADD, Constant.NOT_LOGIN) ;
        }
        return map;
    }

modeljson

package com.MyDoctor.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * DoctorInfo entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "doctor_info", catalog = "doctorla")

public class DoctorInfo implements java.io.Serializable
{
	
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String phnum;
	private String realname;
	private Integer age;
	private String sex;
	private String address="中國";
	private String pmscor="100";
	private String tximg;
	private String txurl;
	private Integer qqnumber;
	private String wechartnumber;
	private String zgnumber;
	private String zgimg;
	private String zgimgurl;
	private String zyzsnumber;
	private String zyzsimg;
	private String zyzsimgurl;
	private String states="no";
	
	// Constructors
	
	/** default constructor */
	public DoctorInfo()
	{
	}
	
	/** full constructor */
	public DoctorInfo(String phnum, String realname, Integer age, String sex, String address, String pmscor,
			String tximg, String txurl, Integer qqnumber, String wechartnumber, String zgnumber, String zgimg,
			String zgimgurl, String zyzsnumber, String zyzsimg, String zyzsimgurl, String states)
	{
		this.phnum = phnum;
		this.realname = realname;
		this.age = age;
		this.sex = sex;
		this.address = address;
		this.pmscor = pmscor;
		this.tximg = tximg;
		this.txurl = txurl;
		this.qqnumber = qqnumber;
		this.wechartnumber = wechartnumber;
		this.zgnumber = zgnumber;
		this.zgimg = zgimg;
		this.zgimgurl = zgimgurl;
		this.zyzsnumber = zyzsnumber;
		this.zyzsimg = zyzsimg;
		this.zyzsimgurl = zyzsimgurl;
		this.states = states;
	}
	
	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	
	@Column(name = "id", unique = true, nullable = false)
	
	public Integer getId()
	{
		return this.id;
	}
	
	public void setId(Integer id)
	{
		this.id = id;
	}
	
	@Column(name = "phnum", length = 11)
	
	public String getPhnum()
	{
		return this.phnum;
	}
	
	public void setPhnum(String phnum)
	{
		this.phnum = phnum;
	}
	
	@Column(name = "realname", length = 50)
	
	public String getRealname()
	{
		return this.realname;
	}
	
	public void setRealname(String realname)
	{
		this.realname = realname;
	}
	
	@Column(name = "age")
	
	public Integer getAge()
	{
		return this.age;
	}
	
	public void setAge(Integer age)
	{
		this.age = age;
	}
	
	@Column(name = "sex", length = 5)
	
	public String getSex()
	{
		return this.sex;
	}
	
	public void setSex(String sex)
	{
		this.sex = sex;
	}
	
	@Column(name = "address")
	
	public String getAddress()
	{
		return this.address;
	}
	
	public void setAddress(String address)
	{
		this.address = address;
	}
	
	@Column(name = "pmscor", length = 50)
	
	public String getPmscor()
	{
		return this.pmscor;
	}
	
	public void setPmscor(String pmscor)
	{
		this.pmscor = pmscor;
	}
	
	@Column(name = "tximg")
	
	public String getTximg()
	{
		return this.tximg;
	}
	
	public void setTximg(String tximg)
	{
		this.tximg = tximg;
	}
	
	@Column(name = "txurl", length = 300)
	
	public String getTxurl()
	{
		return this.txurl;
	}
	
	public void setTxurl(String txurl)
	{
		this.txurl = txurl;
	}
	
	@Column(name = "qqnumber")
	
	public Integer getQqnumber()
	{
		return this.qqnumber;
	}
	
	public void setQqnumber(Integer qqnumber)
	{
		this.qqnumber = qqnumber;
	}
	
	@Column(name = "wechartnumber", length = 200)
	
	public String getWechartnumber()
	{
		return this.wechartnumber;
	}
	
	public void setWechartnumber(String wechartnumber)
	{
		this.wechartnumber = wechartnumber;
	}
	
	@Column(name = "zgnumber", length = 50)
	
	public String getZgnumber()
	{
		return this.zgnumber;
	}
	
	public void setZgnumber(String zgnumber)
	{
		this.zgnumber = zgnumber;
	}
	
	@Column(name = "zgimg")
	
	public String getZgimg()
	{
		return this.zgimg;
	}
	
	public void setZgimg(String zgimg)
	{
		this.zgimg = zgimg;
	}
	
	@Column(name = "zgimgurl", length = 100)
	
	public String getZgimgurl()
	{
		return this.zgimgurl;
	}
	
	public void setZgimgurl(String zgimgurl)
	{
		this.zgimgurl = zgimgurl;
	}
	
	@Column(name = "zyzsnumber", length = 100)
	
	public String getZyzsnumber()
	{
		return this.zyzsnumber;
	}
	
	public void setZyzsnumber(String zyzsnumber)
	{
		this.zyzsnumber = zyzsnumber;
	}
	
	@Column(name = "zyzsimg")
	
	public String getZyzsimg()
	{
		return this.zyzsimg;
	}
	
	public void setZyzsimg(String zyzsimg)
	{
		this.zyzsimg = zyzsimg;
	}
	
	@Column(name = "zyzsimgurl", length = 100)
	
	public String getZyzsimgurl()
	{
		return this.zyzsimgurl;
	}
	
	public void setZyzsimgurl(String zyzsimgurl)
	{
		this.zyzsimgurl = zyzsimgurl;
	}
	
	@Column(name = "states")
	
	public String getStates()
	{
		return this.states;
	}
	
	public void setStates(String states)
	{
		this.states = states;
	}
	
}

  對比後發現,是請求參數和model的參數名稱不一致或者請求參數過少致使的,認真檢查代碼修改便可;session

SpringMVC並不會在控制檯打印出錯誤,因此找起來可能比較麻煩。mvc

相關文章
相關標籤/搜索