zoukankan      html  css  js  c++  java
  • 浅谈Java工具类CommonUtils的使用

    package com.xushouwei.cn;

    import java.util.HashMap;

    import java.util.Map;

    import org.junit.Test;

    import cn.itcast.commons.CommonUtils;

    /**

     * 测试CommonUtils类

     * @author Administrator

     *

     */

    public class CommonUtilsTest {

             /**

              * 测试:返回一个随机32位长得字符串

              * CommonUtils类依赖的jar包

              * 用途:

              * 1.用来做id,数据库表中的主键是不能重复的,它就是不重复的

              * 2.激活码也是不重复的

              *

              */

             @Test

             public void testUuid()

             {

                       String s=CommonUtils.uuid();

                       System.out.println(s);

             }

            

             /**

              * 作用:把一个map中的数据封装大javabean中

              * 要求:要求map中的key名称与javabean中的属性名称相同

              */

             @Test

             public void testToBean()

             {

                       //1.创建map

                       Map<String,Object> map=new HashMap<String,Object>();

                       map.put("pid", "123");

                       map.put("pname", "xushouwei");

                       map.put("age", 25);

                       map.put("xxx", "男");

                       //通过map的数据来创建Person类型的JavaBean对象

                       Person p=CommonUtils.toBean(map, Person.class);

                       System.out.println(p);

             }

    }

  • 相关阅读:
    tableView
    ios设计模式 设计一个应用程序 笔记
    Touching the Background to close the Keyboard
    fdfd
    fdffafadf
    Declaring the Action Method
    网易公开课IOS笔记 第二课
    getters and setters
    objective c
    Google编码规范 C++ Style Guide, JavaScript Style Guide, ObjectiveC Style Guide, and Python Style Guide
  • 原文地址:https://www.cnblogs.com/Jasxu/p/CommonUtils.html
Copyright © 2011-2022 走看看