GetSetUtil

复制代码
package com.jpush;

import cn.jpush.statistics.excel.model.AdSettlementInfoModel;
import cn.jpush.statistics.model.entity.AdSettlementInfo;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class GetSetUtil {
    public static void main(String[] args) {
       setMethod(AdSettlementInfoModel.class,AdSettlementInfo.class,"model","info");

    }
    //            hiveData.setCpc(result.get("cpc"));
    private static void mapToPojo(Class clazz,String target , String mapGet){
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            String name = field.getName();
            char first = name.charAt(0);
            String substring = name.substring(1);
            String pre = Character.toUpperCase(first)+substring;
            System.out.println(target+pre+"("+mapGet+"(\""+name+"\"));");
//            System.out.println("hiveData.set"+pre+"(result.get(\""+name+"\"));");
        }
    }

    
    private static void setMethod(Class sourceClass,Class targetClass,String sourceName,String targeName){
        Method[] sourceMethods = sourceClass.getMethods();
        Method[] targetMethods = targetClass.getMethods();

        Map<String,Method> sourceMethodMap = new HashMap<>();
        Map<String,Method> targetMethodMap = new HashMap<>();
        for (Method sourceMethod : sourceMethods) {
            sourceMethodMap.put(sourceMethod.getName(),sourceMethod);
        }

        for (Method targetMethod : targetMethods) {
            targetMethodMap.put(targetMethod.getName(),targetMethod);
        }


        for (Map.Entry<String, Method> stringMethodEntry : sourceMethodMap.entrySet()) {
            Method method = targetMethodMap.get(stringMethodEntry.getKey());
            if(method == null){
                continue;
            }
            String name = method.getName();
            if(name.startsWith("get") && !"getClass".equals(name)){
                String setName = name.substring(3);
                System.out.println(targeName+".set"+setName+"("+sourceName+"."+name+"());");
            }
        }
        
        
    }
}
复制代码

 

posted @   冬马党  阅读(105)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示