向RestControler Spring MVC发送请求时出现错误请求400错误

时间:2018-03-13 08:50:34

标签: javascript jquery ajax rest

我在使用bad request 400发送请求时出现parameters to controler错误我已经检查了整个sysntax,但我没有遇到任何错误,请查看我的代码有什么不对吗?

var url = contextPath+"/billingControler/getOrdersByResWiseTables";
$.ajax({    
    url      : url,
    data     : "&resID="+$("#rsId").text()+"&tblid="+tableId,  
    type     : "get",     
    dataType : "json" ,
    contentType : 'application/json; charset=utf-8',
    success  : function(response) {             
        console.log(response); 
    } 
}); 

错误:

jquery-3.3.1.min.js?_=1520931033076:2 GET http://localhost:8088/smartpos/billingControler/getOrdersByResWiseTables?&resID=11&tblid=3 400 (Bad Request)

请检查我的java代码

@RequestMapping(value="/getOrdersByResWiseTables", method=RequestMethod.GET,   produces="application/json")

public List<OrderBans> getOrdersByResWiseTables(@RequestParam("resId") String resId,@RequestParam("tblid") String tableid) {   
    String result="";
    logger.debug("Started adding order");

    RestypeIDao pdo = new RestypeIDaoImp();  

    List<OrderBans> orderList = pdo.getOrdersResWIseTbles(resId, tableid);

    System.out.println(orderList);  
    logger.debug("end adding order");
    return orderList;

} 

1 个答案:

答案 0 :(得分:0)

您的网址中有额外的&

此外,您使用的data属性错误,它应该是一个对象。 试试这个:

var url = contextPath+"/billingControler/getOrdersByResWiseTables";
$.ajax({
    url : url,
    data: {
        "resID": $("#rsId").text(),
        "tblid": tableId
    },
    dataType:"json",
    contentType:'application/json; charset=utf-8',
    success:function(response) {
        console.log(response);
    }
});