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;
    }
复制代码

 

posted @   代码猫  阅读(7385)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示