struts2

struts2
一.类型转换
eg:point 自动转换PointAction-conversion.properties  在“-”前面要与一个包下的action同名,里面内容是point = com.test.util.TypeConverter,而TypeConverter是TypeConverter extends DefaultTypeConverter,结构如下:


示例代码如下:
@Override
 public Object convertValue(Map context, Object value, Class toType) {
  if (Point.class == toType) {
   Point point = new Point();
   if (value != null && !"".equals(value)) {
    String[] str = (String[])value;
    String[] val = str[0].split(",");
    if (val != null && 2 == val.length) {
     String x = val[0];
     String y = val[1];
     if (StringUtil.isInteger(x) && StringUtil.isInteger(y)) {
      point.setX(Integer.parseInt(x));
      point.setY(Integer.parseInt(y));
     }
    }
   }
   return point;
  } else if (String.class == toType) {
   StringBuffer sb = new StringBuffer();
   Point point = (Point)value;
   Integer x = point.getX();
   Integer y = point.getY();
   sb.append("[").append(x).append(",").append(y).append("]");
   return sb.toString();
  }
  return null;
 }

总结:
类型转换:    
全局                                                                局部
***Action-conversion.properties             xwork-converison.properties

校验:
***Action.properties                                  message.properies(message名字可任意取,但要在配置)
***Action-validation.xml (配置的元素在package com.opensymphony.xwork2.validator.validators.default.xml里)                          

你可能感兴趣的:(struts2)