方法一:实体类中加日期格式化注解
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birthday;
这种方式在springmvc配置文件中的 中被自动注解实现
方法二:局部配置
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); //true:允许输入空值,false:不能为空值
方法三:全局配置
本文介绍了三种在SpringMVC中进行日期格式化的方案:实体类中加日期格式化注解、局部配置以及全局配置的方法,并详细展示了每种方法的具体实现步骤。
1536

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



