ERROR - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'dojo.book.book_date' on 'class com.ssh.books.web.actions.BooksAction: Error setting expression 'dojo.book.book_date' with value '[Ljava.lang.String;@9d3f8b'
这个不影响存储,只是后台在 <constant name="struts.devMode" value="true" />时报的。
看到网上说了n多,基本也没啥实质的,有的建议是这个不是错误指示log的级别比较高,所以会出来。还有的给写转换类。我说了一下也没用。把类贴出来,这个类是struts在给参数赋值的时候调用的(interceptor)
package com.ssh.commons;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import ognl.DefaultTypeConverter;
@SuppressWarnings("unchecked")
public class DateConverter extends DefaultTypeConverter {
private static final DateFormat[] ACCEPT_DATE_FORMATS = {
new SimpleDateFormat("dd/MM/yyyy"),
new SimpleDateFormat("yyyy-MM-dd"),
new SimpleDateFormat("yyyy/MM/dd") }; //支持转换的日期格式
@Override
public Object convertValue(Map context, Object value, Class toType) {
if (toType == Date.class) { //浏览器向服务器提交时,进行String to Date的转换
Date date = null;
String dateString = null;
String[] params = (String[])value;
dateString = params[0];//获取日期的字符串
for (DateFormat format : ACCEPT_DATE_FORMATS) {
try {
System.out.println(format.parse(dateString).getClass());
return format.parse(dateString);//遍历日期支持格式,进行转换
} catch(Exception e) {
continue;
}
}
return null;
}
else if (toType == String.class) { //服务器向浏览器输出时,进行Date to String的类型转换
Date date = (Date)value;
return new SimpleDateFormat("yyyy-MM-dd").format(date);//输出的格式是yyyy-MM-dd
}
return null;
}
public static void main(String[] argo) throws ParseException{
System.out.println(new SimpleDateFormat("yyyy-MM-dd").parse("2010-11-25"));
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
java.util.Date dt=sdf.parse("2005-2-19");
System.out.print(sdf.format(dt)); //输出结果是:2005-2-19 String
}
}
然后在src下面建立一个xwork-conversion.properties,它会编译到web-inf/class下,里面写上配置java.util.Date=com.ssh.commons.DateConverter