我正在按照本教程创建一个 spring 应用程序
这是我的主课
package com.example.webtool;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
@SpringBootApplication
@EnableSolrRepositories(
basePackages = "com.example.webtool.repository"
)
public class WebtoolApplication {
public static void main(String[] args) {
SpringApplication.run(WebtoolApplication.class, args);
}
}
这是我的存储库类
package com.example.webtool.repository;
import java.util.List;
import org.springframework.data.solr.repository.SolrCrudRepository;
import com.example.webtool.model.Document;
import org.springframework.stereotype.Service;
public interface DocumentRepository extends SolrCrudRepository<Document, String> {
List<Document> findAllByPerson(String person); // find documents whose person name matches the name of the person in the query
List<Document> findAllByRank(String rank); // find documents whose rank matches the rank of the person in the query
}
这是我的文档类
package com.example.webtool.model;
import org.apache.solr.client.solrj.beans.Field;
import org.springframework.data.solr.core.mapping.SolrDocument;
@SolrDocument(solrCoreName = "gettingstarted")
public class Document {
@Field
private String person;
@Field
private String rank;
@Field
private String text;
public Document() { }
public Document(String person, String rank, String text) {
this.person = person;
this.rank = rank;
this.text = text;
}
public String getPerson() {
return person;
}
public void setPerson(String person) {
this.person = person;
}
public String getRank() {
return rank;
}
public void setRank(String rank) {
this.rank = rank;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
陪伴而非守候
相关分类