错误 The request sent by the client was syntactically incorrect.

  今天在做ajax向springmvc发送request请求的时候爆出了这样的一个错误:The request sent by the client was syntactically incorrect.页面显示的是400

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代码

// 用户信息注册
    @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;
    }

model

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的参数名称不一致或者请求参数过少导致的,认真检查代码修改即可;

SpringMVC并不会在控制台打印出错误,所以找起来可能比较麻烦。

 

posted @ 2017-10-16 10:29  码农小正  阅读(1980)  评论(0编辑  收藏  举报