public class myTool { //将obj对象中所有类型为String且值为null的变量,重新赋值为show public static void killNull(Object obj,String show) { Class objClass=obj.getClass(); Field[] fields=objClass.getDeclaredFields(); for(Field f:fields) { if(String.class==f.getType()) { try { f.setAccessible(true); Object value=f.get(obj); if(value==null) { f.set(obj, show); } } catch (Exception e) { e.printStackTrace(); } } } } }