All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.yongzhuzl.commonutil.util.bean.BeanUtil Maven / Gradle / Ivy

Go to download

commonutil是一个功能丰富的Java工具类库,通过封装静态方法,降低学习成本,提升工作效率。

There is a newer version: 4.4.8
Show newest version
package com.gitee.yongzhuzl.commonutil.util.bean;

import java.util.Map;

/**
 * description: Bean操作相关工具类
 * @author 朱正磊
 * @date 2023-09-08 14:27:55
 */
@SuppressWarnings("ALL")
public class BeanUtil {

    /**
     * description: 给Bean指定的属性名设置属性值
     * @author 朱正磊
     * @date 2023-09-08 15:08:09
     * @param bean 实体Bean
     * @param name 属性名
     * @param value 属性值
     * @param  实体Bean泛型
     * @param  属性值泛型
     */
    public static  void setProperty(T bean, String name, V value) {
        cn.hutool.core.bean.BeanUtil.setProperty(bean, name, value);
    }

    /**
     * description: 获取Bean指定属性名的属性值
     * @author 朱正磊
     * @date 2023-09-08 15:08:18
     * @param bean 实体Bean
     * @param name 属性名
     * @return 返回属性值
     * @param  实体Bean泛型
     */
    public static  R getProperty(T bean, String name) {
        return cn.hutool.core.bean.BeanUtil.getProperty(bean, name);
    }

    /**
     * description: 拷贝源对象中的属性值至目标对象(要求属性名要一样)
     * @author 朱正磊
     * @date 2023-09-08 15:08:28
     * @param orig 源对象
     * @param dest 目标对象
     * @param ignoreProperties 可变数组,不需要拷贝的的属性列表
     * @param  源对象泛型
     * @param  目标对象泛型
     */
    public static  void copyProperties(T orig, E dest, String... ignoreProperties) {
        cn.hutool.core.bean.BeanUtil.copyProperties(orig, dest, ignoreProperties);
    }

    /**
     * description: 将Map类型的键值对注入至Bean对象中
     * @author 朱正磊
     * @date 2023-09-08 15:08:41
     * @param map Map对象
     * @param clazz 实体Bean的字节码类型
     * @return 返回Bean对象
     * @param  Map对象值泛型
     * @param  实体Bean泛型
     */
    public static  T mapToBean(Map map, Class clazz) {
        return cn.hutool.core.bean.BeanUtil.toBean(map, clazz);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy