我想通过hibernate,spring mvc和angularJs在h2数据库中存储DateTime列我可以保存以下日期格式2015-01-14但是我想存储这种格式2015-01-14 21:32:29但是我得到这个错误 POST http://loclhost:8080/pagingpoc/app/rest/contacts [HTTP / 1.1 400 Bad Request 24ms]
实体中的字段声明
@Column(name = "updatetimestamp", nullable = false)
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime updatetimestamp;
数据库表中的列名和类型
<column name="UpdateTimestamp" type="timestamp"/>
Spring控制器
@RequestMapping(value = "/rest/contacts",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public void create(@RequestBody Contact contact) {
contactRepository.save(contact);
}
AngularJS服务
pagingpocApp.factory('Contact', function ($resource) {
return $resource('app/rest/contacts/:id', {}, {
'query': { method: 'GET', isArray: true},
'get': { method: 'GET'}
});
});
AngularJS控制器
$scope.create = function () {
Contact.save($scope.contact,
function () {
$scope.contacts = Contact.query();
$('#saveContactModal').modal('hide');
$scope.clear();
});
};
Html页面
<div class="form-group">
<label>Update Timestamp</label>
<input type="text" class="form-control"
ng-model="contact.updatetimestamp">
</div>
答案 0 :(得分:1)
您应该以2015-01-14T21:32:29
格式输入DateTime