java getting a property value using Reflected dynamic entity class

Directly attached to the bar code, if necessary, part of the code can be modified according to their needs:

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;
    }

 

Guess you like

Origin www.cnblogs.com/codecat/p/11497485.html
Recommended