Kevin's blog Kevin's blog
首页
  • AI基础
  • RAG技术
  • 提示词工程
  • Wireshark抓包
  • 常见问题
  • 数据库
  • 代码技巧
  • 浏览器
  • 手册教程
  • 技术应用
  • 流程规范
  • github技巧
  • git笔记
  • vpn笔记
  • 知识概念
  • 学习笔记
  • 环境搭建
  • linux&运维
  • 微服务
  • 经验技巧
  • 实用手册
  • arthas常用
  • spring应用
  • javaAgent技术
  • 网站
友情链接
  • 分类
  • 标签
  • 归档

Kevin

你可以迷茫,但不可以虚度
首页
  • AI基础
  • RAG技术
  • 提示词工程
  • Wireshark抓包
  • 常见问题
  • 数据库
  • 代码技巧
  • 浏览器
  • 手册教程
  • 技术应用
  • 流程规范
  • github技巧
  • git笔记
  • vpn笔记
  • 知识概念
  • 学习笔记
  • 环境搭建
  • linux&运维
  • 微服务
  • 经验技巧
  • 实用手册
  • arthas常用
  • spring应用
  • javaAgent技术
  • 网站
友情链接
  • 分类
  • 标签
  • 归档
  • 手册教程

  • 技术应用

    • 工作杂货

      • Jprofiler排查
      • ES查询压测
      • 阿尔萨斯(Arthas)
      • 定时任务
      • DruidDataSource配置
      • Spring Cloud Stream
      • 线上Tomcat配置参考
      • 配置Prometheus及健康检测
      • Feign远程调用
      • Hystrix单方法熔断配置
      • 本地开发联调配置
      • Java代码杂记
        • 1 类相同属性比较
        • 2 驼峰字符串转下划线字符串
      • SQL脚本杂记
      • 批量算费本地工具类
      • Apollo配置模糊查询
      • 开发问题记录
      • 机器配置参考
    • 技巧备忘

  • 流程规范

  • GitHub技巧

  • VPN

  • Git笔记

  • 实用手册
  • 技术应用
  • 工作杂货
luoxiaofeng
2022-05-11
目录

Java代码杂记

# 1 类相同属性比较

public class Test {
  public static void main(String[]args)throws NoSuchFieldException {
    Map<String, String> map1 = new HashMap<>();
    Field[] fields = OmsOrderApiVO.class.getDeclaredFields();
    for (Field field : fields) {
      String fieldName = field.getName();
      ApiModelProperty annotation = field.getAnnotation(ApiModelProperty.class);
      String val = "-";
      if (annotation != null) {
        val = annotation.value();
      }
      map1.put(fieldName, val);
    }

    Map<String, String> map2 = new HashMap<>();
    Field[] fields2 = OmsWaybillApiDTO.class.getDeclaredFields();
    for (Field field2 : fields2) {
      String fieldName = field2.getName();
      ApiModelProperty annotation = field2.getAnnotation(ApiModelProperty.class);
      String val = "-";
      if (annotation != null) {
        val = annotation.value();
      }
      map2.put(fieldName, val);
    }
  }
}
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

# 2 驼峰字符串转下划线字符串

public class Test {
  public static void main(String[] args) throws NoSuchFieldException {
    Map<String, String> map1 = new HashMap<>();
    Field[] fields = SpmCashBillDetail.class.getDeclaredFields();
    for (Field field : fields) {
      String fieldName = field.getName();
      System.out.println(toUnderlineCase(fieldName).toUpperCase());
    }
  }

  public static String toUnderlineCase(String camelCaseStr) {
    if (camelCaseStr == null) {
      return null;
    }
    // 将驼峰字符串转换成数组
    char[] charArray = camelCaseStr.toCharArray();
    StringBuffer buffer = new StringBuffer();
    //处理字符串
    for (int i = 0, l = charArray.length; i < l; i++) {
      if (charArray[i] >= 65 && charArray[i] <= 90) {
        buffer.append("_").append(charArray[i] += 32);
      } else {
        buffer.append(charArray[i]);
      }
    }
    return buffer.toString();
  }
}
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
上次更新: 2022/06/02, 11:20:10
本地开发联调配置
SQL脚本杂记

← 本地开发联调配置 SQL脚本杂记→

最近更新
01
AI是如何学习的
06-06
02
提示词工程实践指南
06-06
03
chatGpt提示原则
06-06
更多文章>
| Copyright © 2022-2025 Kevin | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式