1. 工具類
import java.lang.reflect.Field;
public class BeanUtils {
// 獲取實體類的值,並且以逗號分隔
public static String getModelValue(Object model) throws IllegalAccessException {
StringBuffer modelValue = new StringBuffer();
for (Field field : model.getClass().getDeclaredFields()) {
field.setAccessible(true);
//field.getName() 獲取屬性名
modelValue.append(field.get(model)).append(",");
}
return modelValue.toString();
}
}
2. 需引入的依賴
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>