小编moh*_*moh的帖子

Spring 3.1 JSON日期格式

我正在使用带注释的Spring 3.1 MVC代码(spring-mvc),当我通过@RequestBody发送日期对象时,日期显示为数字.这是我的控制器

@Controller
@RequestMapping("/test")
public class MyController {

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class,
                  new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
    }


    @RequestMapping(value = "/getdate", method = RequestMethod.GET)
    public @ResponseBody Date getDate(@RequestParam("dt") Date dt, Model model) {
        // dt is properly constructed here..
        return new Date();
    }
}
Run Code Online (Sandbox Code Playgroud)

当我通过日期时,我能够以格式收到日期.但我的浏览器将日期显示为数字

1327682374011
Run Code Online (Sandbox Code Playgroud)

如何以我为webbinder注册的格式显示日期?我在一些论坛上看到我应该使用杰克逊映射器,但我不能改变现有的映射器?

java spring spring-mvc

31
推荐指数
3
解决办法
4万
查看次数

标签 统计

java ×1

spring ×1

spring-mvc ×1