我正在使用Spring 3.1.1.RELEASE。我有一个带有两个java.util.Date字段的模型......
public class MyModel
{
...
private java.util.Date startDate;
private java.util.Date meetingTime;
如何设置活页夹,以便根据不同的日期格式转换每个字段?目前我有
@InitBinder
public void initBinder(WebDataBinder binder) {
final DateFormat dateFormat = new SimpleDateFormat(dateFormat1);
dateFormat.setLenient(false);
但这不起作用,因为我希望使用不同的格式转换每个字段。谢谢, - 戴夫
答案 0 :(得分:0)
您可以使用@DateTimeFormat
@DateTimeFormat(pattern = "dd/MM/yyyy")
private java.util.Date startDate;
@DateTimeFormat(pattern = "dd MMM yyyy")
private java.util.Date meetingTime;
如果您使用的是早于3.2的Spring,则可能需要在classpath上包含joda-time