我有Java和字段activeRecord
private Boolean activeRecord;
@Override
public Boolean isActiveRecord() {
return activeRecord;
}
@Override
public void setActiveRecord(Boolean activeRecord) {
this.activeRecord = activeRecord;
}当我在列表中发送它时,作为Jasper报告数据源
List<Branch> dataList = new BranchLogic().selectAll();
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList);我得到了错误信息
net.sf.jasperreports.engine.JRException:从bean: activeRecord检索字段值时出错。……由: java.lang.NoSuchMethodException:属性'activeRecord‘在类’activeRecord‘中没有getter方法引起
为什么Jasper不承认isActiveRecord是一种getter方法?
发布于 2016-09-03 13:34:49
前缀is...可用于返回基本boolean的方法。但是,您的字段activeRecord是Boolean类型的,它是一个对象(boolean的包装器类型),对于对象,您总是需要使用get...。
来自JavaBeans规范,8.3.2:
此外,对于
boolean属性,我们允许一个getter方法来匹配模式: 公共布尔是(); 可以提供此is<PropertyName>方法而不是get<PropertyName>方法,也可以提供get<PropertyName>方法之外的方法。
因此,您有两个可能的解决方案:
activeRecord成为一个boolean,并保留getter isActiveRecord()。如果activeRecord不能是null,这将是首选的方法。Boolean,但将方法isActiveRecord()重命名为getActiveRecord()。您需要确保调用方正确地处理null。https://stackoverflow.com/questions/39307379
复制相似问题