我使用spring boot,spring数据,twitter bootstrap,并使用rest。 我试着发表一份表格
<form id="contactInformationForm" class="form-horizontal" role="form" data-fv-framework="bootstrap" data-fv-icon-valid="glyphicon glyphicon-ok" data-fv-icon-invalid="glyphicon glyphicon-remove" data-fv-icon-validating="glyphicon glyphicon-refresh">
<div class="form-group">
<label for="lodgerFirstName" class="col-sm-3 control-label">Prénom</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="lodgerFirstName" name="firstName" placeholder="Entrer le prénom">
</div>
</div>
<div class="form-group">
<label for="lodgerLastName" class="col-sm-3 control-label">Nom</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="lodgerLastName" name="lastName" placeholder="Entrer le nom">
</div>
</div>
...
$('#lodgerSave').on('click', function (e) {
jQuery.ajax({
type: "post",
url: "http://localhost:8080/lodgers",
contentType: "application/json",
data: $('#contactInformationForm').serialize(),
dataType: 'json',
success: function (data, status, jqXHR) {
},
error: function (jqXHR, status) {
}
});
e.preventDefault();
});
在服务器端
@RequestMapping(value = "/lodgers", method = RequestMethod.POST)
public LodgerInformation createLodger(@RequestBody @Valid final LodgerInformation lodgerDto) {
return lodgerService.save(lodgerDto);
}
我的dto
public class LodgerInformation {
private long lodgerId;
private String firstName;
private String lastName;
private Date birthdate;
private long statusId;
private Date startDate;
private Date releaseDate;
private Phone contactPersonelMobile;
private List<IdentityCardDto> identityCardList;
当我发布时,我收到此错误消息
"{"timestamp":1436293673415,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Unrecognized token 'firstName': was expecting 'null', 'true', 'false' or NaN\n at [Source: java.io.PushbackInputStream@424485fa; line: 1, column: 11]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'firstName': was expecting 'null', 'true', 'false' or NaN\n at [Source: java.io.PushbackInputStream@424485fa; line: 1, column: 11]","path":"/lodgers"}"
firstName字段存在于web部分和dto,任何想法?