1、创建Point类(bean)
2、Action继承ActionSupport
3、建立转换器
4、配置转换器
1、
public class Point {
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
2、
public class PointAction extends ActionSupport{
private Point point;
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
public String execute(){
return "success";
}
}
3、
public class PointConverter extends DefaultTypeConverter{
@Override
public Object convertValue(Map context, Object target, Member member,
String propertyName, Object value, Class toType) {
if (Point.class==toType) {
String[] str = (String[])value;
String firstValue = str[0];
String[] resultValue = firstValue.split(",");
Point point = new Point();
point.setX(Integer.parseInt(resultValue[0]));
point.setY(Integer.parseInt(resultValue[0]));
return point;
}else if (String.class==toType) {
Point point = (Point) value;
int x = point.getX();
int y = point.getY();
String result = "x:"+x+"y:"+y;
return result;
}
return null;
}
}
4.
局部转换器在包下
PointAction-conversion.properties
point=com.openwudi.converter.PointConverter
全局转换器在/src下
xwork-conversion.properties
com.openwudi.bean.Point=com.openwudi.converter.PointConverter
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。