PropertyUtilsBean.setSimpleProperty(Object bean, String name, Object value)) . , ( public ).
:
import org.apache.commons.beanutils.PropertyUtils;
import java.lang.reflect.InvocationTargetException;
class FileDt {
String reportName;
String reportLocation;
public String getReportName() {
return reportName;
}
public void setReportName(String reportName) {
this.reportName = reportName;
}
public String getReportLocation() {
return reportLocation;
}
public void setReportLocation(String reportLocation) {
this.reportLocation = reportLocation;
}
public static void main(String[] args) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
FileDt dt = new FileDt();
PropertyUtils.setSimpleProperty(dt, "reportName", "abc.html");
PropertyUtils.setSimpleProperty(dt, "reportLocation", "c://");
}
}
, :
Exception in thread "main" java.lang.NoSuchMethodException: Property 'reportName' has no setter method in class 'class FileDt'
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)
at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:928)
at FileDt.main(FileDt.java:28)
public :
import org.apache.commons.beanutils.PropertyUtils;
import java.lang.reflect.InvocationTargetException;
public class FileDt {
String reportName;
String reportLocation;
public String getReportName() {
return reportName;
}
public void setReportName(String reportName) {
this.reportName = reportName;
}
public String getReportLocation() {
return reportLocation;
}
public void setReportLocation(String reportLocation) {
this.reportLocation = reportLocation;
}
public static void main(String[] args) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
FileDt dt = new FileDt();
PropertyUtils.setSimpleProperty(dt, "reportName", "abc.html");
PropertyUtils.setSimpleProperty(dt, "reportLocation", "c://");
}
}