Struts2(批量类型转换器struts2.3.4)
批量类型转换器
package com.wildcat.converter;import java.util.ArrayList;import java.util.List;import java.util.Map;import java.util.StringTokenizer;import org.apache.struts2.util.StrutsTypeConverter;import com.wildcat.bean.User;public class UserConverter3 extends StrutsTypeConverter {@Overridepublic Object convertFromString(Map arg0, String[] arg1, Class arg2) {List <User> list=new ArrayList<User>();User user=new User();for (String value:arg1){StringTokenizer ST=new StringTokenizer(value,";");String username=ST.nextToken();String password=ST.nextToken();user.setPassword(password);user.setUsername(username);list.add(user);}return list;}@Overridepublic String convertToString(Map arg0, Object arg1) {List<User> list=(List<User>)arg1;StringBuffer buffer=new StringBuffer();for (User u:list){String username=u.getUsername();String password=u.getPassword();buffer.append("姓名: ").append(username).append("Password: ").append(password);}return buffer.toString();}}