请问高手?(关于对javaBean的操作)!!!!!!!!!!! 不太明白什么意思,但是如果有个BEAN,就想知道里面的属性和方法的话,我想可以有很多办法:1。导入到一个IDE工具中直接看2。用javadoc 去生成一个文档3。写一个类去返回该BEAN的属性,这个就是昨天的贴子里面有个介绍4。用对JAVABEAN操作的工具 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 fogs(菜鸟想飞) 你严重误解我的意思 treeroot(旗鲁特) 有没有代码 让我参考 使用反射beanName.get("properties"),beanName.set("properties") public void test1(){ try { Class cl = Class.forName("test.myjavaBean"); Object o = cl.newInstance(); Method[] mts = cl.getMethods(); String strTemp = ""; int namePos = 0; for (int i = 0; i < mts.length; i++) { strTemp = mts[i].getName(); if ( (namePos = strTemp.indexOf("set")) >= 0 || (namePos = strTemp.indexOf("Set")) >= 0 || (namePos = strTemp.indexOf("SET")) >= 0) { System.out.println(mts[i].getReturnType().getName()); if (mts[i].getReturnType().getName().equals( "java.lang.String")) o = this.fillObject("好的给你赋了", "java.lang.String", "set" + strTemp.substring(3, strTemp.length()), o); if (mts[i].getReturnType().getName().equals("int")) o = this.fillObject(new Integer(12345), "java.lang.Integer", "set" + strTemp.substring(3, strTemp.length()), o); } } //bean属性列表 Field[] fs = cl.getFields(); for (int j = 0; j < fs.length; j++) { System.out.println("属性类型:"+fs[j].getType()); System.out.println("属性名称:" + fs[j].getName()); } } catch (Exception e) { e.printStackTrace(); } } public Object fillObject(Object value, String type, String method, Object o) { try { String newm = "g" + method.substring(1); //System.out.println("type: " + type + " " + newm); //System.out.println("type: " + type + " " + method); if (type.equals("java.lang.Boolean")) { (o.getClass().getMethod(method, new Class[] {boolean.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.lang.Double")) { (o.getClass().getMethod(method, new Class[] {double.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.lang.Float")) { (o.getClass().getMethod(method, new Class[] {float.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.lang.Integer")) { System.out.println("整形赋值" + value); (o.getClass().getMethod(method, new Class[] {int.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.lang.Long")) { (o.getClass().getMethod(method, new Class[] {long.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.lang.String")) { (o.getClass().getMethod(method, new Class[] {String.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.math.BigDecimal")) { (o.getClass().getMethod(method, new Class[] {BigDecimal.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.sql.Date")) { (o.getClass().getMethod(method, new Class[] {Date.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.sql.Time")) { (o.getClass().getMethod(method, new Class[] {Time.class})). invoke(o, new Object[] {value}); } else if (type.equals("java.sql.Timestamp")) { (o.getClass().getMethod(method, new Class[] {Timestamp.class})). invoke(o, new Object[] {value}); } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } return o; } 求用牛顿法解方程的代码 再问,有关数据类型转换的小问题 排序问题 找的快疯了,谁能告诉我一下我这程序到底错在哪里啊~~ SWING如何才能隐藏窗体的关闭按钮呢? 问个很菜的问题,莫笑,马上结贴 谁能告诉sql server 驱动程序下载地和驱动drivername是什么 jboss-3.0.1_tomcat-4.0.4的默认WEB目录在哪儿? How to convert MS Word to Html in java by programming? 成绩等级 怎样建立一个远程目录?? HibernateUtil.currentSession()的错误!
try {
Class cl = Class.forName("test.myjavaBean");
Object o = cl.newInstance();
Method[] mts = cl.getMethods(); String strTemp = "";
int namePos = 0;
for (int i = 0; i < mts.length; i++) {
strTemp = mts[i].getName();
if ( (namePos = strTemp.indexOf("set")) >= 0
|| (namePos = strTemp.indexOf("Set")) >= 0
|| (namePos = strTemp.indexOf("SET")) >= 0) {
System.out.println(mts[i].getReturnType().getName());
if (mts[i].getReturnType().getName().equals(
"java.lang.String"))
o = this.fillObject("好的给你赋了", "java.lang.String",
"set" +
strTemp.substring(3, strTemp.length()),
o);
if (mts[i].getReturnType().getName().equals("int"))
o = this.fillObject(new Integer(12345),
"java.lang.Integer",
"set" +
strTemp.substring(3, strTemp.length()),
o); }
}
//bean属性列表
Field[] fs = cl.getFields();
for (int j = 0; j < fs.length; j++) {
System.out.println("属性类型:"+fs[j].getType());
System.out.println("属性名称:" + fs[j].getName());
} }
catch (Exception e) {
e.printStackTrace();
} } public Object fillObject(Object value, String type, String method, Object o) {
try {
String newm = "g" + method.substring(1);
//System.out.println("type: " + type + " " + newm);
//System.out.println("type: " + type + " " + method);
if (type.equals("java.lang.Boolean")) {
(o.getClass().getMethod(method, new Class[] {boolean.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.lang.Double")) {
(o.getClass().getMethod(method, new Class[] {double.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.lang.Float")) {
(o.getClass().getMethod(method, new Class[] {float.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.lang.Integer")) {
System.out.println("整形赋值" + value);
(o.getClass().getMethod(method, new Class[] {int.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.lang.Long")) {
(o.getClass().getMethod(method, new Class[] {long.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.lang.String")) {
(o.getClass().getMethod(method, new Class[] {String.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.math.BigDecimal")) {
(o.getClass().getMethod(method, new Class[] {BigDecimal.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.sql.Date")) {
(o.getClass().getMethod(method, new Class[] {Date.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.sql.Time")) {
(o.getClass().getMethod(method, new Class[] {Time.class})).
invoke(o, new Object[] {value});
}
else if (type.equals("java.sql.Timestamp")) {
(o.getClass().getMethod(method, new Class[] {Timestamp.class})).
invoke(o, new Object[] {value});
}
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
catch (NoSuchMethodException e) {
e.printStackTrace();
} return o;
}