admin9527 最近的时间轴更新
admin9527

admin9527

V2EX 第 219180 号会员,加入于 2017-03-06 13:25:52 +08:00
admin9527 最近回复了
2017-04-06 09:44:29 +08:00
回复了 wly19960911 创建的主题 Java 关于 spring MVC 的 @RequestBody 接收 json, Date 类无法转换的问题
@cs4814751 恩,是的,没注意,原来都是用在 ajax 表单提交上的
2017-04-06 09:37:00 +08:00
回复了 wly19960911 创建的主题 Java 关于 spring MVC 的 @RequestBody 接收 json, Date 类无法转换的问题
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);

SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
datetimeFormat.setLenient(false);

binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(dateFormat, true));
binder.registerCustomEditor(java.sql.Timestamp.class,new CustomDateEditor(datetimeFormat, true));
}
可以在控制 controller 上加注解,注入的时候应该就会自动转了,不过想想直接用 string 接收方便多了。
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5266 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 07:54 · PVG 15:54 · LAX 00:54 · JFK 03:54
Developed with CodeLauncher
♥ Do have faith in what you're doing.