我在我的项目中使用solrj
并遵循this教程,我创建了一个对象类
public class Student {
@Field String id;
public Student(String studentId) {
this.id = studentId;
}
//setter and getter methods here
}
并使用以下代码从Solr检索数据并将响应绑定到Student
对象
final SolrClient client = getSolrClient();
final SolrQuery query = new SolrQuery("*:*");
query.addField("id");
final QueryResponse response = client.query("collection-name", query);
final List<Student> students = response.getBeans(Student.class);
我在最后一行收到错误。 org.apache.solr.client.solrj.beans.BindingException: Could not instantiate object of class Student
但是,当我将public Student() { }
构造函数添加到Student类时,它工作正常。我的问题是,为什么它不能在第一种情况下工作或为什么有必要在这里创建一个非参数构造函数?
在所有solrj ref指南中,有一个示例,它有空构造函数,但没有描述。我认为api在获取数据之前调用空构造函数并逐个填充字段。