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)));
}
});
}

本文介绍在SpringMVC框架中如何解决通过@RequestParam接收的时间戳参数默认为string类型的问题,提供了一个自定义转换器的解决方案,确保能正确将时间戳转换为Date类型。
1万+

被折叠的 条评论
为什么被折叠?



