SpringMVC 查询参数接收时间戳转Date方法

Spring mvc 通过 @RequestParam 接收 参数指定类型为Date时,接口传入时间戳 会默认为string类型,无法转为Date,可在controller中添加如上转换器。

 @InitBinder
    public void initBinder(final WebDataBinder webdataBinder) {
        webdataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
            @Override
            public void setAsText(String text) throws IllegalArgumentException {
                setValue(new Date(Long.valueOf(text)));
            }
        });
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章