zoukankan      html  css  js  c++  java
  • trim-all-strings-elements-in-a-complex-object

    package com.xxx.common.util;
    
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.lang3.StringUtils;
    
    import java.lang.reflect.Field;
    
    /**
     * @version 1.0.0
     * @date 2021-01-15 17:53
     */
    @Slf4j
    public class TrimUtil {
        public static void trimStringFieldInObject(Class<?> clazz, Object t) {
            Field[] fields = clazz.getClass().getFields();
            for (Field field : fields) {
                try {
                    if (field.get(t) instanceof String) {
                        Object o = field.get(t);
                        String s = (String) o;
                        field.set(t, StringUtils.trimToEmpty(s));
                    }
                } catch (IllegalAccessException e) {
                    log.warn("converting field {} error", field.getName());
                }
            }
        }
    }

    https://stackoverflow.com/questions/9189520/trim-all-strings-elements-in-a-complex-object

  • 相关阅读:
    梯度下降法
    超平面
    感知机模型
    三角不等式
    统计学习方法基本概念
    Kaggle 的注册和使用
    win10 部署 Anaconda
    全概率和贝叶斯公式
    行列式
    伴随矩阵
  • 原文地址:https://www.cnblogs.com/exmyth/p/14283666.html
Copyright © 2011-2022 走看看