当前位置: 代码迷 >> Web前端 >> Struts2(批量门类转换器struts2.3.4)
  详细解决方案

Struts2(批量门类转换器struts2.3.4)

热度:259   发布时间:2013-11-08 17:51:58.0
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 {

	@Override
	public 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;
	}

	@Override
	public 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();
	}

}

  相关解决方案