1. 对OGNL操作进行封装完成OGNL表达式所表示值到Java对象值传递机制
2. 在参数传递过程中做恰当类型转化保证页面上串能够转化成各式各样Java对象
接下来通过 4个区别角度来具体讲述Struts2在这两个方面工作
目 录 [ - ]
最简单参数传递
Array、List、Map等容器类型参数传递
文件上传
自定义类型转化实现
最简单参数传递
public EnumTypeConverter extends DefaultTypeConverter {
/**
* Converts the given object to a given type. How this is to be done is implemented in toClass. The OGNL context, o
* and toClass are given. This method should be able to handle conversion in general without any context or object
* specied.
*
* @param context - OGNL context under which the conversion is being done
* @param o - the object to be converted
* @param toClass - the that contains the code to convert to enumeration
* @ Converted value of type declared in toClass or TypeConverter.NoConversionPossible to indicate that the
* conversion was not possible.
*/
public Object convertValue(Map context, Object o, Class toClass) {
(o instanceof String) {
convertFromString(((String) o)[0], toClass);
} (o instanceof String) {
convertFromString((String) o, toClass);
}
super.convertValue(context, o, toClass);
}
/**
* Converts _disibledevent="Struts2中参数传递" />
/**
* context - OGNL context under which the conversion is being done
* target - target object in which the property is being
* member - member (Constructor, Method or Field) being
* propertyName - property name being
* value - value to be converted
* toType - type to which value is converted
*/
public Object convertValue(Map context, Object target, Member member, String propertyName, Object value, Class toType);
延伸阅读
最新评论