之前的是局部类型转换。
现在要全局类型转换:xwork-conversion.properties,直接建立在src下:
com.test.bean.Point = com.test.converter.PointConverter
查看struts2本身的类型转换机制文档:org.apache.struts2.util
看一下基础的抽象类,接口什么的。重写抽象方法
关联源代码:src/core/src/main/java/org/apache/struts2
写一个PointConverter2继承strutsTypeConverter
在PointAction中有一个private List<Point> point;point是一个集合类型。new一个PointConverter3
PointConverter中public Object convertFromString(...)
{
List<Point> list = new ArrayList<Point>();
for(String value:values)
{
Point point = new Point();
String[] paramValues = value.split(",");
int x = Integer.parseInt(paramValues[0]);
int y = Integer.parseInt(paramValues[1]);
point.setX(x);
point.setX(y);
list.add(point);
}
return list;
}
public ...convertToString(...)
{
List<Point> list = (List<Point>)o;
StringBuilder sb = new StringBuilder();
int number=0;
sb.append("[") ;
for(Point point: list)
{
++number;
int x = point.getX();
int y = point.getY();
String result = "[x="+x+" ,y="+y+"]";
sb.append(number).append(" x=").append(x).append(", y=").append(y).append(" ");
}
sb.append("]");
return sb.toString();
}
}