java - 通过 hibernate 将 DateTime 列存储在 h2 数据库中

标签 java angularjs spring hibernate h2

我想通过 hibernate、spring mvc 和 angularJs 将 DateTime 列存储在 h2 数据库中我可以保存以下日期格式 2015-01-14 但我想存储此格式 2015-01-14 21:32:29 但我收到此错误 发布http://loclhost:8080/pagingpoc/app/rest/contacts [HTTP/1.1 400 错误请求 24 毫秒]

实体中的字段声明

@Column(name = "updatetimestamp", nullable = false)
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime  updatetimestamp;

数据库表中的列名称和类型

        <column name="UpdateTimestamp" type="timestamp"/>

Spring Controller

@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 Controller

  $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>

最佳答案

您应该按以下格式输入日期时间 2015-01-14T21:32:29

关于java - 通过 hibernate 将 DateTime 列存储在 h2 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28069091/

相关文章:

java - 同时调用时的 JVM 方法调用内部结构

Java Eclipse MySQL语法错误异常

java - 在 @OneToMany 上返回一个空列表,该列表确实是 0 到多个(可为空)

xml - 单个文件的 Maven 资源过滤

java - transient 域实例jpa&spring

java - 从 ArrayList 中删除重复项

java - 使用带有 Java 的 Google Drive API,如何仅列出驱动器部分/文件夹中的文件

javascript - 如何隐藏和显示 map 在 angular 1.x 中使用 angularjs-google-maps

angularjs - Azure 中的 Angular 连接设置

javascript - 字符串匹配 angularjs/javascript 最多 2 个字符