//将rs中的值封装成一个集合
public static Collection getDatas(Collection result, ResultSet rs, Class clazz) {
try {
while (rs.next()) {
//创建类的实例
Object vo = clazz.newInstance();
//获取本对象的属性
Field[] fields = clazz.getDeclaredFields();
//获取父类的属性
Field[] superFields = clazz.getSuperclass().getDeclaredFields();
//父类的属性和自己的属性相加
Field[] allFields = addFields(superFields, fields);
//遍历所有的属性
for (Field field : allFields) {
//获得setter方法的方法名
String setterMethodName = getSetterMethodName(field.getName());
System.out.println("DataUtil类中getDatas函数1:"+setterMethodName);
//获得setter方法
Method setterMethod = clazz.getMethod(setterMethodName, field.getType());
System.out.println("DataUtil类中getDatas函数2:"+setterMethod.getName());
invokeMethod(rs, field, vo, setterMethod);
}
result.add(vo);
}
rs.close();
} catch (Exception e) {
System.out.println("DataUtil类中getDatas函数3:"+e.getMessage());
e.printStackTrace();
System.out.println("DataUtil类中getDatas函数4:"+e.getMessage());
throw new DataException(e.getMessage());
}
return result;
}
DataUtil类中getDatas函数1:setID
DataUtil类中getDatas函数2:setIDDataUtil类中getDatas函数1:setUSER_NAME
DataUtil类中getDatas函数2:setUSER_NAME
DataUtil类中getDatas函数1:setUSER_PASSWORD
DataUtil类中getDatas函数2:setUSER_PASSWORD
goodDaoImpl中findAll函数的SQL语句=:SELECT * FROM T_good good ORDER BY good.ID desc
DataUtil类中getDatas函数1:setID
DataUtil类中getDatas函数2:setID
DataUtil类中getDatas函数1:setGood_NAME
DataUtil类中getDatas函数3:com.good.vo.good.setGood_NAME(java.lang.String)
java.lang.NoSuchMethodException: com.good.vo.good.setGood_NAME(java.lang.String)
at java.lang.Class.getMethod(Class.java:1605)
at com.good.commons.DataUtil.getDatas(DataUtil.java:40)
at com.good.dao.impl.CommonDaoImpl.getDatas(CommonDaoImpl.java:28)
at com.good.dao.impl.goodDaoImpl.findAll(goodDaoImpl.java:36)
at com.good.service.impl.goodServiceImpl.getAll(goodServiceImpl.java:46)
at com.good.ui.SalePanel.buildgoodsComboBox(SalePanel.java:453)
at com.good.ui.SalePanel.<init>(SalePanel.java:161)
at com.good.ui.MainFrame.<init>(MainFrame.java:136)
at com.good.ui.LoginFrame.login(LoginFrame.java:112)
at com.good.ui.LoginFrame$1.actionPerformed(LoginFrame.java:91)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6134)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5899)
at java.awt.Container.processEvent(Container.java:2023)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895)
at java.awt.Container.dispatchEventImpl(Container.java:2067)
at java.awt.Window.dispatchEventImpl(Window.java:2458)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
DataUtil类中getDatas函数4:com.good.vo.good.setGood_NAME(java.lang.String)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)