开发者

spring json date to java date object

开发者 https://www.devze.com 2023-03-06 03:36 出处:网络
In my Spring[3.0] application, I want to submit data using jquery.ajax. Spring is interpreting this request and converting to appropriate Object. however, it is unable to parse the date attributes.

In my Spring[3.0] application,

I want to submit data using jquery.ajax. Spring is interpreting this request and converting to appropriate Object. however, it is unable to parse the date attributes. How do I pass them from my JSON request to java? please help...

public class MyUser{
    public String name;
    public Date birth;
}

@RequestMapping("/app/saveuser")
public String save(@ModelAttribute MyUser user)
{
    //User has NO date.. :(
}

Front end code... 
jQuery.post("/app/saveuser", 
{name:"myName", birth:new Date()},
function(data){
    alert(data);
} );
开发者_运维问答


Dates cannot be bound to a command object unless you specify a PropertyEditor or a Conversion service that can read some date format (this is a limitation by design, as you cannot tell what '01/02/03' means without knowing the format); try to write some @InitBinder method and there register a CustomDateEditor for the format you're expecting.

0

精彩评论

暂无评论...
验证码 换一张
取 消