2013年(92)
分类: 信息化
2013-02-24 02:31:00
[代码] 用java反射机制和正则表达式完成PHP式query句子 package jaakan.util; public class ReadClassAttribute { /** * @param args */ public static String readAttribute(Object obj,String attributeName){ ; String value=null; try { java.lang.reflect.Field field=obj.getClass().getDeclaredField(attributeName); field.setAccessible(true); value=(String)field.get(obj); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return value; } public static void main(String[] args) { // TODO Auto-generated method stub } } ;