⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 converter.java

📁 本文论述了一个前台笔记本销售系统的开发过程
💻 JAVA
字号:
package com.set.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.beanutils.converters.StringConverter;
import org.apache.log4j.Logger;

import com.set.appframe.exception.SystemException;

/**
 * 
 * <p>
 * Title:
 * </p>
 * <p>
 * Description: 用于系统中PO与VO之间的属性拷贝操作
 * </p>
 * <p>
 * Copyright: Copyright (c) 2004
 * </p>
 * <p>
 * Company: SET
 * </p>
 * 
 * @author zhifeng
 * @version 1.0
 */
public class Converter {
	private static Logger logger = Logger.getLogger(Converter.class);

	public Converter() {
	}

	public static Object converVO2PO(Object vo, Object po)
			throws SystemException {
		try {
			BeanUtils.copyProperties(po, vo);
			Object id = PropertyUtils.getProperty(po, "id");
			if (null == id || "".equals(id)) {
				PropertyUtils.setProperty(po, "id", null);
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new SystemException("error.attributenotmatch");
		}
		return po;
	}

	public static Object converPO2VO(Object po, Object vo)
			throws SystemException {
		try {
			BeanUtils.copyProperties(vo, po);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new SystemException("error.attributenotmatch");
		}
		return vo;
	}

	public static List batchConvertPO2VO(List pos, Class voClass)
			throws SystemException {
		if (null == pos) {
			return null;
		}
		ArrayList list = new ArrayList();

		Iterator it = pos.iterator();
		Object tempVO;
		try {
			for (; it.hasNext();) {
				tempVO = voClass.newInstance();
				BeanUtils.copyProperties(tempVO, it.next());
				list.add(tempVO);
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new SystemException("error.attributenotmatch");
		}
		return list;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -