我尝试使用json值
的数据调用urldataExist值为
“{”name“:”Robert Trudeau“,”birthdate“:”1991-02-12“}”
if (memberFullName != "" && memberBirthdate != "") {
dataExist = JSON.stringify({name: memberFullName, birthdate: memberBirthdate});
//check if user exist, it not we continue otherwise we should not
jQuery.ajax({
type: "get",
url: getHostName() + "/members/validation",
contentType: "application/json",
data: dataExist,
dataType: 'json',
success: function (data, status, jqXHR) {
alert(status);
},
error: function (jqXHR, status) {
checkError(jqXHR);
}
});
}
在服务器上我有
@GetMapping(value = "/members/validation")
public ResponseEntity<Void> hasUsernameExist(@RequestBody String name, @RequestBody LocalDate birthdate) {
boolean existing = memberService.hasMemberExist(name, birthdate);
if (!existing) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
通话结束后,我
Object {readyState:4,responseText:“”,status:400,statusText:“error”},status =“error
答案 0 :(得分:-1)
如果你不覆盖某个类,Spring不能处理多个Request Body。
在控制器端,您需要添加类来放置所有字段。
这里,MemberSearchExistingDto可以有name和birthdate字段。
在html中:
dataExist = JSON.stringify({memberSearchExisting:{name: memberFullName, birthdate: memberBirthdate}});