我将JSON传递给Spring控制器时得到Status Code:400 Bad Request
。
JSP中的脚本:
var retailerId = $("#retailerId").val();
var retailerStatus = $("#retailerStatus").val();
var firstName = $("#firstName").val();
var lastName = $("#lastName").val();
var drvLicense = $("#drvLicense").val();
var ssn = $("#ssn").val();
var dob = $("#dob").val();
var json = {
"retailerId" : retailerId,
"retailerStatus" : retailerStatus,
"firstName" : firstName,
"lastname" : lastName,
"drvLicense" : drvLicense,
"ssn" : ssn,
"dob" : $.datepicker.formatDate('yy-mm-dd', dob)
};
$("#spinner").show();
$.ajax({
url : "adminsearchOwner/searchOwners",
type : "POST",
dataType : 'json',
contentType : 'application/json',
data : json = JSON.stringify(json),
success : function(data) {
alert(111);
},
error : function() {
$("#spinner").hide();
}
});
控制器
@Controller
public class AdminSearchOwnersController {
private static final Logger LOGGER = Logger.getLogger(AdminSearchOwnersController.class);
/**
*
* @param webDataBinder
*/
@ModelAttribute("ownerSearchDTO")
public OwnerSearchDTO getOwneSearchDTOr() {
return new OwnerSearchDTO();
}
@RequestMapping(value = "/auth/adminsearchOwner", method = RequestMethod.GET)
public ModelAndView showSearchOwnerForm() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("auth/managelicense/searchOwnerForm");
return modelAndView;
}
@RequestMapping(value = "/auth/adminsearchOwner/searchOwners", method = RequestMethod.POST)
public @ResponseBody
String searchOwner(@RequestBody OwnerSearchDTO ownerSearchDTO, HttpSession session) {
Collection<OwnerSearchDTO> list = new ArrayList<OwnerSearchDTO>();
return "";
}
}
但是控件不会转到控制器类的searchOwner()
方法。谁能帮我这个?我在过去的3天里一直在努力。