我试图将投影与@Query
结合起来,我得到的是NoConverterFoundException
。我在文档中找不到特别不允许的地方。我知道我可以将Project
投射到ProjectItem
,因为如果我在没有@Query
注释的情况下做同样的事情就可以了。我是否需要专门为此注册转换器?
我的存储库接口
public interface ProjectRepository extends JpaRepository<Project, Integer> {
// Doesn't work?
@Query("select p from Project p")
public List<ProjectItem> findAllForTest();
// Work's okay.
public List<ProjectItem> findAllBy();
}
DTO:
public class ProjectItem {
private final Integer projectId;
private final String projectName;
private final String techstack;
@JsonCreator
public ProjectItem(
@JsonProperty("projectId") Integer projectId,
@JsonProperty("projectName") String projectName,
@JsonProperty("techstack") String techstack
) {
this.projectId = projectId;
this.projectName = projectName;
this.techstack = techstack;
}
public Integer getProjectId() {
return projectId;
}
public String getProjectName() {
return projectName;
}
public String getTechstack() {
return techstack;
}
}
错误
2018-05-07 10:23:02.047 ERROR 9668 --- [o-auto-1-exec-4] oaccC [。[。[/]。[dispatcherServlet]:servlet的Servlet.service()[ dispatcherServlet]在path []的上下文中引发异常[请求处理失败;嵌套异常是org.springframework.core.convert.ConverterNotFoundException:没有找到能够从类型[employeeproject.model.Project]转换为类型[project.item.ProjectItem]]并具有根本原因的转换器