通过反射遍历实体类的属性并得到属性值集合
封装成一个方法: // 通过反射遍历实体类的属性并得到属性值集合,去除业务无关主键值 public static List<String> getContentsList(Object model) throws Exception { List<String> values = new ArrayList<String>() ; // 获取实体类的所有属性,返回Field数组 Field[] field = model .getClass () .getDeclaredFields () ; // 遍历所有属性 for (int j = 0 ; j < field.length; j++) { // 获取属性的名字 String name = field[j] .getName () ; // 过滤掉id/createDate/creater属性 if (!( "id" .equals (name))) { // 将属性的首字符大写,方便构造get, set 方法 name = name .substring ( 0 , 1 ) .toUpperCase () + name .substring ( 1 ) ; // 获取属性的类型 String type = field[j] .getGenericType () .toString () ; // System .out