1.UUID
1.静态方法uuid() 随机生成由数字和字符组成的32位字符串
2.依赖的jar包:commons-beanutils.jar 、commons-logging.jar
String str=CommonUtils.uuid();
2.toBean
1.tobean能用map集合对bean进行赋值
2.其中map的键为bean的属性名称(成员变量)。Map中的值(value)为bean属性中的值
class Person{
private String name;
private String age;
private String sex;
//所有属性的 set() //get()方法
}
class TestCommonUtils{
@Test
public void testToBean(){
Map<String,object> map=new HashMap<String,object>();
map.put("name","张三");
map.put("age","18");
map.put("sex","男");
CommonUtils.toBean(map,Person.class);
System.out.println(p);
输出的结果为:张三,18,男
}
}
当Map中没有Bean的属性时候,Bean的属性为null如下:
@Test
public void testToBean(){
Map<String,object> map=new HashMap<String,object>();
map.put("name","张三");
map.put("age","18");
CommonUtils.toBean(map,Person.class);
System.out.println(p);
输出的结果为:张三,18,null
}
map能为多个Bean进行赋值,
class Student{
private String sid;
private String height;
private String weight;
//所有属性的 set() //get()方法
}
@Test
public void testToBean(){
Map<String,object> map=new HashMap<String,object>();
//为Person的属性赋值
map.put("name","张三");
map.put("age","18");
//为Student赋值
map.put("sid","123456");
map.put("height","180");
map.put("weight","130");
CommonUtils.toBean(map,Person.class);
System.out.println("person="+p);
System.out.println("Student="+Student)
输出的结果为:person=张三,18,null
Student=123456,180,130;
}