
|  |      1Citrus      2017-04-06 08:53:14 +08:00 via iPhone 打异常栈啊。。。光说 415 没用呀。。。 | 
|  |      2watzds      2017-04-06 08:59:14 +08:00 via Android  1 可能缺少一个处理时间的 jar 包 | 
|  |      3watzds      2017-04-06 09:00:36 +08:00 via Android 好像是 Joda | 
|  |      4acrisliu      2017-04-06 09:01:04 +08:00 via Android  1 试试自定义 JsonDeserialize 。 另外 Google 一下的话, stack overflow 上很多解决方案,不懂楼主为啥说搜不到有用的资料,难道我用的假的搜索引擎? | 
|  |      5yang2yang      2017-04-06 09:02:43 +08:00  1 | 
|  |      6Infernalzero      2017-04-06 09:03:00 +08:00  1 @RequestBody 就可以的,你一定是传的参数有问题,注意 Date 类的 set 方法,前端传的时间参数必须是 timeInMillis 的 long 类型才能转换,而且这里需要设置 ContentType 为 appliction/json | 
|  |      7DRcoding      2017-04-06 09:03:34 +08:00 把 model 里的 Date 类型改成 String | 
|  |      8wly19960911 OP | 
|  |      9wly19960911 OP @Infernalzero  感谢提供信息,到时候查一下看看。 contenttype 确定是 json ,就是时间没有处理好。 @DRcoding model 我不希望能改变数据类型,我想使用 spring 自定义的转换器或者其他方法解决最好。 | 
|      10stoldog      2017-04-06 09:09:04 +08:00 请求的时候加个 contentType | 
|      11cs4814751      2017-04-06 09:21:01 +08:00  1 用 Jackson 然后用 @JsonSerialize 配合自己实现的 JsonSerializer 的 serialize 方法 google 可以搜到具体用法 | 
|  |      12happypy1      2017-04-06 09:21:30 +08:00  1 写个单元测试,把出了问题的 json 文本 serialize 成那个 model ,看看是否成功。 | 
|  |      13johnj      2017-04-06 09:24:49 +08:00 你的日期是什么格式? | 
|  |      14wly19960911 OP | 
|  |      15wly19960911 OP @johnj  使用的是 “ yyyy-MM-dd ” 的格式。 | 
|      16admin9527      2017-04-06 09:37:00 +08:00 @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); datetimeFormat.setLenient(false); binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(dateFormat, true)); binder.registerCustomEditor(java.sql.Timestamp.class,new CustomDateEditor(datetimeFormat, true)); } 可以在控制 controller 上加注解,注入的时候应该就会自动转了,不过想想直接用 string 接收方便多了。 | 
|      17cs4814751      2017-04-06 09:37:28 +08:00  1 | 
|  |      19wly19960911 OP | 
|      21cs4814751      2017-04-06 09:45:23 +08:00 @wly19960911 @admin9527 我看岔了 是要反序列化 initbinder 好用 脑抽了以为是序列化 | 
|  |      22wly19960911 OP @admin9527  使用表单的话我是测试过可以正常接收,我突然发现自己有点脑抽为什么要用 json 接收 Date ,不过趁机了解这个不会有坏处, get 和 post 方法在 model 使用 @DatetimeFormat 和 controller 上使用 @ModelAttribute 能接收到。 | 
|      23hiro0729      2017-04-06 10:03:47 +08:00  1 spring mvc 默认用的是 jackson 来解析 json 的,所以 Date 的解析得下面这么用 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezOne= "GMT+8") private Date lastupdatetime; | 
|  |      24jelinet      2017-04-06 13:29:09 +08:00 同意 timeInMillis long 类型。 |