java利用反射动态获取实体类的属性值


直接贴代码吧,有需要的话,可以根据自己的需要修改部分代码:

public BigDecimal getByAttributeName(ThmdGwqriR thmdGwqriR, String attributeName){
        for (Field field : thmdGwqriR.getClass().getDeclaredFields()) {
            field.setAccessible(true);
            try{
                if (attributeName.toLowerCase().equals(field.getName().toLowerCase())){
                    return new BigDecimal(field.get(thmdGwqriR).toString());
                }
            }
            catch (Exception e){
                e.printStackTrace();
                return null;
            }
        }
        return null;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM