使用AngularJS,Spring和Hibernate保存房间预订

馄饨87

设想:

预约由用于特定房间用户预订。保留实体具有以下属性:

private Long reservationId;
private Date startTime;
private Date endTime;
private User user;
private Room room;
private String note;

如您所见,预订实体也接受了User和Room实体。我正在尝试将此预订保存到数据库中,但保存后继续运行以下内容:

HTTP Status 400 -description The request sent by the client was syntactically incorrect.

我认为我的问题与错误地传递User和Room对象有关,但是我还不能准确地找出问题所在。

这是我的Spring @RestController方法:

@RequestMapping(method=RequestMethod.POST)
public ResponseEntity<ReservationResource> addReservation(@RequestBody ReservationResource reservation){
    try{
        Reservation newReservation = reservationService.addReservation(reservation.toReservation());
        ReservationResource reservationResource = new ReservationResourceAsm().toResource(newReservation);

        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(URI.create(reservationResource.getLink("self").getHref()));
        return new ResponseEntity<ReservationResource>(reservationResource, headers, HttpStatus.CREATED);
    } catch (ReservationExistsException exception) {
        throw new ConflictException(exception); 
    }
}

这是我的Angular控制器:

.controller('AddReservationController', function($scope, $state, $http, reservationService){
    $scope.reservation = {};

    $http.get("/libroomreserve/api/user/1").then(
        function(resource){
            console.log(resource);
            $scope.reservation.user = resource.data;
        },
        function(){
            $scope.reservation.user = null;
        }
    );
    $http.get("/libroomreserve/api/room/1").then(
        function(resource){
            $scope.reservation.room = resource.data;
        },
        function(){
            $scope.reservation.room = null;
        }
    );

    $scope.newReservation = function(){
    reservationService.addReservation(
        $scope.reservation,
        function(data){
            console.log("Success! Data printing:");
            console.log(data);
            $state.go("home");
        },
        function(data){
            console.log("Failure! Data printing:");
            console.log(data);
        }
    );
};
});

以及相应的Angular工厂服务:

.factory('reservationService', function($resource){
var reservations = {};

reservations.addReservation = function(reservation, success, failure){
    var Reservation = $resource('/libroomreserve/api/reservation');
    Reservation.save({}, reservation, success, failure);
};

return reservations;
})

最后,这是请求有效负载,我通过验证程序运行了其内容,并检出了它:

{"user":{"userId":1,"userName":"tom","links":[{"rel":"self","href":"http://localhost:8080/libroomreserve/api/user/1"}]},"room":{"roomId":1,"roomNumber":"101A","roomDescription":"Best room ever","roomCapacity":15,"links":[{"rel":"self","href":"http://localhost:8080/libroomreserve/api/room/1"}]},"startTime":"2015-12-25 00:00:00","endTime":"2015-12-25 00:00:00","note":"dsfds"}

更新

这是在发布预订时log4j返回的一堆错误。似乎与开始日期和结束日期有关。

    DispatcherServlet with name 'dispatcher' processing POST request for [/libroomreserve/api/reservation]
Looking up handler method for path /api/reservation
Returning handler method [public org.springframework.http.ResponseEntity<com.ucrisko.libroomreserve.rest.resources.ReservationResource> com.ucrisko.libroomreserve.rest.controllers.ReservationController.addReservation(com.ucrisko.libroomreserve.rest.resources.ReservationResource)]
Returning cached instance of singleton bean 'reservationController'
Skip CORS processing, request is a same-origin one
Read [class com.ucrisko.libroomreserve.rest.resources.ReservationResource] as "application/json;charset=UTF-8" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@ec39299]
Error resolving argument [0] [type=com.ucrisko.libroomreserve.rest.resources.ReservationResource]
HandlerMethod details: 
Controller [com.ucrisko.libroomreserve.rest.controllers.ReservationController]
Method [public org.springframework.http.ResponseEntity<com.ucrisko.libroomreserve.rest.resources.ReservationResource> com.ucrisko.libroomreserve.rest.controllers.ReservationController.addReservation(com.ucrisko.libroomreserve.rest.resources.ReservationResource)]

org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"])
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:224)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:208)
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:193)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:148)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:125)
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78)
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:399)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:162)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"])
    at com.fasterxml.jackson.databind.exc.InvalidFormatException.from(InvalidFormatException.java:55)
    at com.fasterxml.jackson.databind.DeserializationContext.weirdStringException(DeserializationContext.java:904)
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseDate(StdDeserializer.java:787)
    at com.fasterxml.jackson.databind.deser.std.DateDeserializers$DateBasedDeserializer._parseDate(DateDeserializers.java:175)
    at com.fasterxml.jackson.databind.deser.std.DateDeserializers$DateDeserializer.deserialize(DateDeserializers.java:261)
    at com.fasterxml.jackson.databind.deser.std.DateDeserializers$DateDeserializer.deserialize(DateDeserializers.java:245)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:520)
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:337)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:131)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3731)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2808)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:221)
    ... 76 more
Resolving exception from handler [public org.springframework.http.ResponseEntity<com.ucrisko.libroomreserve.rest.resources.ReservationResource> com.ucrisko.libroomreserve.rest.controllers.ReservationController.addReservation(com.ucrisko.libroomreserve.rest.resources.ReservationResource)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"])
Resolving exception from handler [public org.springframework.http.ResponseEntity<com.ucrisko.libroomreserve.rest.resources.ReservationResource> com.ucrisko.libroomreserve.rest.controllers.ReservationController.addReservation(com.ucrisko.libroomreserve.rest.resources.ReservationResource)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"])
Resolving exception from handler [public org.springframework.http.ResponseEntity<com.ucrisko.libroomreserve.rest.resources.ReservationResource> com.ucrisko.libroomreserve.rest.controllers.ReservationController.addReservation(com.ucrisko.libroomreserve.rest.resources.ReservationResource)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"])
Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"])
SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
Handler execution resulted in exception: Could not read document: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation (error: Failed to parse Date value '2015-12-25 00:00:00': Can not parse date "2015-12-25 00:00:00": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 at [Source: java.io.PushbackInputStream@1f05a63c; line: 1, column: 295] (through reference chain: com.ucrisko.libroomreserve.rest.resources.ReservationResource["startTime"])
Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
Successfully completed request
Chain processed normally
SecurityContextHolder now cleared, as request processing completed
克莱里斯-谨慎乐观-

该错误消息非常具体:

Can not construct instance of java.util.Date from String value '2015-12-25 00:00:00': not a valid representation

默认情况下,Jackson尝试将日期映射到ISO-8601:

standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))

您需要注释所讨论的属性,以告诉Jackson使用哪种格式。这样的事情应该起作用:

@JsonFormat(shape=Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

同时使用Hibernate和Spring数据jpa?

来自分类Dev

使用Hibernate和Spring实现乐观锁

来自分类Dev

在Spring Security和Hibernate中使用jdbcAuthentication

来自分类Dev

使用哪个Spring和Hibernate版本

来自分类Dev

检查房间是否免费(预订教室)

来自分类Dev

使用Spring MVC和Hibernate实现分页

来自分类Dev

使用Spring MVC和Hibernate Rest服务从数据库保存和检索图像

来自分类Dev

使用STOMP在Spring的多个房间

来自分类Dev

Spring MVC:使用Hibernate在PostgreSQL中保存Java列表

来自分类Dev

在Spring和Hibernate中使用TransactionProxyFactoryBean

来自分类Dev

使用angularjs和spring boot上传文件

来自分类Dev

使用Hibernate和Spring更新

来自分类Dev

如何使用Oracle SQL约束检查酒店房间是否已预订

来自分类Dev

MySQL:如何为每个房间选择(续订预订数和所有预订数)?

来自分类Dev

是否可以使用spring jms停止和重新启动持久预订?

来自分类Dev

根据预订系统中的可用房间打印HTML表格

来自分类Dev

使用Spring MVC和Hibernate Rest服务从数据库保存和检索图像

来自分类Dev

使用JPA和Hibernate的Spring Security

来自分类Dev

在预订应用程序中保存房间

来自分类Dev

MySQL在预订系统中寻找免费房间

来自分类Dev

MySQL预订系统:获取可用的房间

来自分类Dev

使用MySQL和Hibernate进行Spring Boot

来自分类Dev

使用Spring MVC转换和保存日期

来自分类Dev

使用 Domino 数据服务 REST API 创建房间预订

来自分类Dev

在 AngularJS 和 Spring 中将 Hibernate 对象作为 @RequestBody

来自分类Dev

使用 Spring REST 和 Angularjs 显示 PDF

来自分类Dev

使用 JNDI 和 Hibernate 配置 Spring

来自分类Dev

房间预订检查

来自分类Dev

预订和管理

Related 相关文章

热门标签

归档