看板 java 關於我們 聯絡資訊
一個很簡單的 jObject class Pojo { public Pojo(){} private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } 試圖利用apache的beanutils, get value by PropertyName import org.apache.commons.beanutils.PropertyUtils; @Test public void TestGetProperty() { Pojo testCase_2 = new Pojo(); testCase_2.setName("my name is google"); try { System.out.println(testCase_2.getName()); String name = (String) PropertyUtils.getSimpleProperty(testCase_2,"name"); } catch (Exception e) { e.printStackTrace(); } } 結果出現Error java.lang.NoSuchMethodException: Property 'name' has no getter method in class 'class info.diywork.test.Pojo' at org.apache.commons.beanutils.PropertyUtilsBean. getSimpleProperty(PropertyUtilsBean.java:1327) at org.apache.commons.beanutils.PropertyUtils. getSimpleProperty(PropertyUtils.java:611) 上網G很久,請問要怎麼使用BeanUtitls getVal by name 自問自答: 因為Pojo 不是Public Class 囧~~~~~~~~~~~~~~~~~ ※ 編輯: pttnews (49.216.167.103), 12/16/2015 16:57:57