查询数据库时需要查所有字段,又不想用select * form 一个一个取字段难免太麻烦,而且该了表结构就得动sql
public static String getAllAttrsNoClassName(@SuppressWarnings("rawtypes") Class c) { StringBuilder s = new StringBuilder(); Field[] fs = c.getDeclaredFields(); for (int i = 0; i < fs.length; i++) { Field f = fs[i]; Annotation annotation = f.getAnnotation(TableField.class); if (annotation == null) {// 非表字段 continue; } f.setAccessible(true); // 设置些属性是可以访问的 s.append(","); s.append(f.getName()); } return s.toString().substring(1, s.length()); }