我正在尝试在存储库界面中使用findByFieldName生成的方法。我在编译时收到此错误:
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property source found for type Article!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
我的文章模型如下:
package com.infostream.models;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
@Entity
@Table(name = "articles")
public class Article extends Base {
private String ref_id;
public String getRef_id() {
return ref_id;
}
public void setRef_id(String ref_id) {
this.ref_id = ref_id;
}
public Article() {
}
public Article(String source_id, String ref_id, String title, String subject, String description, String url) {
this.source_id = source_id;
this.ref_id = ref_id;
this.title = title;
this.subject = subject;
this.description = description;
this.url = url;
}
public String getSource_id() {
return source_id;
}
public void setSource_id(String source_id) {
this.source_id = source_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@NotNull
private String source_id;
@NotNull
private String title;
private String subject;
private String description;
@NotNull
private String url;
}
我定义findByFieldName的界面如下所示:
package com.infostream.repositories;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.infostream.models.Article;
import java.lang.String;
public interface ArticleRepositoryImpl extends PagingAndSortingRepository<Article, Long> {
Page<Article> findAll(Pageable pageRequest);
Page<Article> findBySource_id(String source_id, Pageable pageable);
}
正如您在上面的模型中所看到的,source_id是在模型中定义的。
在运行应用程序的主类上,我已经为jpa存储库定义了地点。
package com.infostream;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@EnableJpaRepositories("com.infostream.repositories")
public class InfoStreamSpringBootApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(InfoStreamSpringBootApplication.class, args);
}
}
有没有人有他们如何实现这一目标的源代码示例?