maploader.java

来自「Jodd是一个开源的公用Java基础类库」· Java 代码 · 共 31 行

JAVA
31
字号
package jodd.bean.loaders;

import java.util.Iterator;
import java.util.Map;

import jodd.bean.BeanUtil;

/**
 * Populate java bean using objects that are implementation of Map interface.
 * <p>
 * Properties in Map object are defined as follows:
 * each key of Map object is a string the represents a bean property name and
 * keys value is an object that represents bean property value.
 */
public class MapLoader implements jodd.bean.Loader {

	public void load(Object bean, Object map) {
		if (map instanceof Map) {
			Iterator i = ((Map)map).keySet().iterator();
			while (i.hasNext()) {
				String propertyName = (String) i.next();
                Object propertyValue = ((Map)map).get(propertyName);
				if (propertyValue == null) {
					return;
				}
				BeanUtil.setProperty(bean, propertyName, propertyValue);
			}
		}
	}
}

⌨️ 快捷键说明

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