### Question:
BeanUtils extends org.springframework.beans.BeanUtils { public static void setBeanProperties(Object bean, Map<? extends Object, ? extends Object> map) { if (map == null) { return; } PropertyDescriptor[] targetPds = getPropertyDescriptors(bean.getClass()); for (PropertyDescriptor targetPd : targetPds) { Method writeMethod = targetPd.getWriteMethod(); if (writeMethod != null) { Object value = map.get(targetPd.getName()); if (value == null) { continue; } Class<?>[] parameterTypes = writeMethod.getParameterTypes(); if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } try { if (parameterTypes[0].isPrimitive()) { if (parameterTypes[0] == Integer.TYPE) { value = Integer.parseInt(value.toString()); } else if (parameterTypes[0] == Boolean.TYPE) { value = Boolean.parseBoolean(value.toString()); } else if (parameterTypes[0] == Character.TYPE) { value = Character.valueOf(value.toString().charAt(0)); } else if (parameterTypes[0] == Byte.TYPE) { value = Byte.parseByte(value.toString()); } else if (parameterTypes[0] == Short.TYPE) { value = Short.parseShort(value.toString()); } else if (parameterTypes[0] == Long.TYPE) { value = Long.parseLong(value.toString()); } else if (parameterTypes[0] == Float.TYPE) { value = Float.parseFloat(value.toString()); } else if (parameterTypes[0] == Double.TYPE) { value = Double.parseDouble(value.toString()); } else { throw new NumberFormatException(); } } writeMethod.invoke(bean, new Object[]{ value}); } catch (NumberFormatException e) { log.error(e.getMessage(), e); } catch (Throwable e) { log.error(e.getMessage(), e); } } } }  static void setBeanProperties(Object bean, Map<? extends Object, ? extends Object> map);  }### Answer:
@Test public void testSetBeanProperties() { TestBean testBean = new TestBean(); int intProp = 123; long longProp = 1234567891; double doubleProp = 12345.6789; boolean boolProp = true; float floatProp = 12345.6789f; byte byteProp = Byte.parseByte("1"); String strProp = "123456789"; Map<String, Object> propMap = new HashMap<String, Object>(); propMap.put("intProp", intProp); propMap.put("longProp", longProp); propMap.put("doubleProp", doubleProp); propMap.put("boolProp", boolProp); propMap.put("floatProp", floatProp); propMap.put("byteProp", byteProp); propMap.put("strProp", strProp); BeanUtils.setBeanProperties(testBean, propMap); Assert.assertEquals("TestBean 属性(intProp)值应该为: " + intProp, intProp, testBean.getIntProp()); Assert.assertEquals("TestBean 属性(longProp)值应该为: " + longProp, longProp, testBean.getLongProp()); Assert.assertEquals("TestBean 属性(boolProp)值应该为: " + boolProp, boolProp, testBean.isBoolProp()); Assert.assertEquals("TestBean 属性(byteProp)值应该为: " + byteProp, byteProp, testBean.getByteProp()); Assert.assertEquals("TestBean 属性(strProp)值应该为: " + strProp, strProp, testBean.getStrProp()); Assert.assertTrue("TestBean 属性(doubleProp)值应该为: ", longProp == testBean.getLongProp()); Assert.assertTrue("TestBean 属性(floatProp)值应该为: ", floatProp == testBean.getFloatProp()); }