• mybatis


    写底层通用方法/框架,借鉴方法

    PropertyNamer

    // getxxx setxxx 转属性名 
    
      public static String methodToProperty(String name) {
        if (name.startsWith("is")) {
          name = name.substring(2);
        } else if (name.startsWith("get") || name.startsWith("set")) {
          name = name.substring(3);
        } else {
          throw new ReflectionException("Error parsing property name '" + name + "'.  Didn't start with 'is', 'get' or 'set'.");
        }
    
        if (name.length() == 1 || (name.length() > 1 && !Character.isUpperCase(name.charAt(1)))) {
          name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
        }
    
        return name;
      }
    
      public static boolean isProperty(String name) {
        return isGetter(name) || isSetter(name);
      }
    
      public static boolean isGetter(String name) {
        return (name.startsWith("get") && name.length() > 3) || (name.startsWith("is") && name.length() > 2);
      }
    
      public static boolean isSetter(String name) {
        return name.startsWith("set") && name.length() > 3;
      }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    PropertyCopier

    
      public static void copyBeanProperties(Class type, Object sourceBean, Object destinationBean) {
        Class parent = type;
        while (parent != null) {
          final Field[] fields = parent.getDeclaredFields();
          for (Field field : fields) {
            try {
              try {
                field.set(destinationBean, field.get(sourceBean));
              } catch (IllegalAccessException e) {
                if (Reflector.canControlMemberAccessible()) {
                  field.setAccessible(true);
                  field.set(destinationBean, field.get(sourceBean));
                } else {
                  throw e;
                }
              }
            } catch (Exception e) {
              // Nothing useful to do, will only fail on final fields, which will be ignored.
            }
          }
          parent = parent.getSuperclass();
        }
      }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    
      private void addSetMethods(Method[] methods) {
        Map> conflictingSetters = new HashMap<>();
        Arrays.stream(methods).filter(m -> m.getParameterTypes().length == 1 && PropertyNamer.isSetter(m.getName()))
          .forEach(m -> addMethodConflict(conflictingSetters, PropertyNamer.methodToProperty(m.getName()), m));
        resolveSetterConflicts(conflictingSetters);
      }
    
      private void addMethodConflict(Map> conflictingMethods, String name, Method method) {
        if (isValidPropertyName(name)) {
          List list = MapUtil.computeIfAbsent(conflictingMethods, name, k -> new ArrayList<>());
          list.add(method);
        }
      }
    
    ## MapUtil      map里套 list, get时,list 有则返回,无则 初始化
    public class MapUtil {
    
      public static  V computeIfAbsent(Map map, K key, Function mappingFunction) {
        V value = map.get(key);
        if (value != null) {
          return value;
        }
        return map.computeIfAbsent(key, mappingFunction);
      }
    
      /**
       * Map.entry(key, value) alternative for Java 8.
       */
      public static  Entry entry(K key, V value) {
        return new AbstractMap.SimpleImmutableEntry<>(key, value);
      }
    
      private MapUtil() {
        super();
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    在这里插入图片描述

    二级目录

    借用spring 的解析器,解析 #{ 和 }

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述

    三级目录

  • 相关阅读:
    接口测试详解
    如何使用Iptables在Linux网关上转发端口
    JMeter笔记14 | JMeter场景设计和设置
    灌区流量监测设备:农田灌溉的“智慧眼”
    保证数据库质量安全:从0开始的数据测试
    最长递增子序列
    [附源码]计算机毕业设计企业售后服务管理系统Springboot程序
    Java架构师内功计算机网络
    FFmpeg入门及编译
    Linux内核之tasklet机制
  • 原文地址:https://blog.csdn.net/nalanxiaoxiao2011/article/details/133013781