• 2017/2/7 专注力培养 每日总结规划


      上午主要围绕着validate查看相关资料,缘由是之前有一个通用的属性校验利用java反射机制做的,但是却只能校验pojo的第一层属性,如果pojo中包含另外的成员类就无法校验此成员内部的属性。

    public static String validateInputParameters(Object request_pojo,Map<String,String> validatePairs,String request_id) {
            if(request_pojo == null){
                log.error(String.format("uuid %s:请求json为空",request_id));
                return "请求参数为空!";
            }
            try {
                for(Map.Entry<String, String> entry : validatePairs.entrySet()){
                    Object value = ReflectUtils.getValueByFieldName(request_pojo, entry.getKey());
                    if(value==null || StringUtils.isEmpty(value.toString())){
                        log.error(String.format("uuid %s: 请参参数有误,%s",request_id, entry.getValue()));
                        return entry.getValue();
                    }else if(value instanceof List<?>){
                        if(((List<?>)value).size()==0){
                            log.error(String.format("uuid %s: 请参参数有误,%s",request_id, entry.getValue()));
                            return entry.getValue();
                        }
                    }
                }
            } catch (Exception e) {
                log.error(String.format("uuid %s:系统错误,验证必填入参时出错", request_id),e);
                return "系统繁忙!";
            }
            
            return OrderContants.SUCCESS;
        }

    public static Object getValueByFieldName(Object obj, String fieldName) {
            Field field = getFieldByName(obj, fieldName);
            Object value = null;
            if(field == null) {
                return null;
            }
            try {
                /* 通过一对存储器方法(getter / setter)导出的一个属性 */
                PropertyDescriptor descriptor = new PropertyDescriptor(fieldName, obj.getClass());
                value = descriptor.getReadMethod().invoke(obj, new Object[] {});
            } catch (IllegalAccessException e) {
                logger.info(e.getMessage());
            } catch (IllegalArgumentException e) {
                logger.info(e.getMessage());
            } catch (InvocationTargetException e) {
                logger.info(e.getMessage());
            } catch (IntrospectionException e) {
                logger.info(e.getMessage());
            }
            return value;
        }

    在寻找方案的时候发现自己看着看着 思想就跑远了,刚过完年发现自己进入状态很慢,有点精神涣散。如何看待工作?business。

    下午从java api入手 开始是Object 延伸到 Class,

  • 相关阅读:
    request和response使用
    oracle_to_char
    oracl_LTRIM_RITRIM
    convert
    jdbc
    oracle_trunc
    [python]glob模块中的glob()函数为什么返回空列表??
    win10 anaconda+tensorflow+keras
    Golang学习:sublime text3配置golang环境
    2018/12/05学习笔记
  • 原文地址:https://www.cnblogs.com/Luke-wang/p/6373368.html
Copyright © 2020-2023  润新知