小编joh*_*kyr的帖子

无法使用@DateTimeFormat(pattern ="dd/MM/yyyy")在java.util.Date中转换字符串

我有一个简单POJO的日期字段.我想用一个表单中的值绑定对象.
在我使用jquery ui datepicker日期格式("dd/mm/yyyy")的形式中
我有console.log值并且是一个字符串:13-11-2014
我正在使用spring 4.0.7
我的依赖关系joda-time 2.5

我得到这个例外:

Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.format.annotation.DateTimeFormat java.util.Date for value '22-11-2014'; nested exception is java.lang.IllegalArgumentException: Invalid format: "22-11-2014" is malformed at "-11-2014"]
Run Code Online (Sandbox Code Playgroud)

我的POJO:

    package gr.gsis.announcement.model;


    import java.io.Serializable;
    import java.util.Date;

    import org.springframework.format.annotation.DateTimeFormat;

    public class Announcement implements Serializable{

        private static final long serialVersionUID = …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

spring ×1

spring-mvc ×1