All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lone.common.util.ReplaceToJson Maven / Gradle / Ivy

The newest version!
package com.lone.common.util;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

/**
 * 
 *
 */
public class ReplaceToJson {

		
	/**
     * 方法描述:  值替换工具
     * 作    者: zym
     * @param objList
     * @param perFieldName
     * @param sufFieldName
     * @return 格式:old_new,old2_new2
     * 返回类型: String
     */
	public static String listToReplaceStr(List objList, String perFieldName, String sufFieldName){
		List strList = new ArrayList();
		for (Object object : objList) {
			String perStr = null;
			String sufStr = null;
			try {
				perStr = (String)PropertyUtils.getProperty(object, perFieldName);
				sufStr = (String)PropertyUtils.getProperty(object, sufFieldName);
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
			strList.add(perStr + "_" +sufStr);
		}
		return StringUtils.join(strList, ",");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy