import lombok.extern.slf4j.Slf4j; import java.lang.reflect.Field; import java.lang.reflect.Method; @Slf4j public class Hsetman { public static void main(String[] args) throws Exception { Hsetman hsetman = new Hsetman(); HalfmonthMaintitem model = new HalfmonthMaintitem(); hsetman.setDefaultValue(model, "5"); System.out.println(model.getHm20() + "-" + model.getHm2() + ":" + model.getHm7()); } private <T> void setDefaultValue(T t, String value) throws Exception { Field[] field = t.getClass().getDeclaredFields(); for (int j = 0; j < field.length; j++) { String name = field[j].getName(); name = name.substring(0, 1).toUpperCase() + name.substring(1); Method n = t.getClass().getMethod("set" + name, String.class); n.invoke(t, value); } } }