Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot JPA查询错误-“;无财产'';找到类型为''&引用;例外情况_Java_Spring_Spring Boot_Spring Data Jpa_Illegalargumentexception - Fatal编程技术网

Java Spring Boot JPA查询错误-“;无财产'';找到类型为''&引用;例外情况

Java Spring Boot JPA查询错误-“;无财产'';找到类型为''&引用;例外情况,java,spring,spring-boot,spring-data-jpa,illegalargumentexception,Java,Spring,Spring Boot,Spring Data Jpa,Illegalargumentexception,我目前正在学习一门使用SpringDataJPA的在线SpringBoot课程 我的项目包括两个实体:BDProject和BDUser,它们具有多对一关系。尝试从用户id查找项目时,将显示以下异常 例外情况 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'BDProjectController': Unsatisfied dependency expr

我目前正在学习一门使用SpringDataJPA的在线SpringBoot课程

我的项目包括两个实体:BDProject和BDUser,它们具有多对一关系。尝试从用户id查找项目时,将显示以下异常

例外情况

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'BDProjectController': Unsatisfied dependency expressed through field 'bdProjectService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'BDProjectService': Unsatisfied dependency expressed through field 'bdProjectRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'BDProjectRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.project.bdproject.BDProjectRepository.findByUserID(java.lang.String)! No property userID found for type BDProject!
我花了数小时试图找出导致此异常的原因,但似乎没有任何东西可以修复它

我的代码:

实体

@Entity
public class BDUser {


@Id
private String userID;
private String bdUsername;
private String bdUserEmail;
private String bdUserPassword;

public BDUser(){
}

public BDUser(String userID, String bdUsername, String bdUserEmail, String bdUserPassword) {
    super();
    this.userID = userID;
    this.bdUsername = bdUsername;
    this.bdUserEmail = bdUserEmail;
    this.bdUserPassword = bdUserPassword;
}
// getters and setters...

@Entity
public class BDProject {

@Id
private String proID;
private String proName;
private String proCodeOwner;
private String proIDs;
@ManyToOne
private BDUser bdUser;

public BDProject() {
}

public BDProject(String proID, String proName, String proCodeOwner, String proIDs, String userID) {
    super();
    this.proID = proID;
    this.proName = proName;
    this.proCodeOwner = proCodeOwner;
    this.proIDs = proIDs;
    this.bdUser = new BDUser(userID, "", "", "");
}
// getters and setters...
控制器

@RestController
public class BDProjectController {

@Autowired
private BDProjectService bdProjectService;

@RequestMapping("/bdusers/{userID}/bdprojects")
public List<BDProject> getAllProjects(@PathVariable String proID){
    return bdProjectService.getAllProjects(proID);
}

@RequestMapping("/bdusers/{userID}/bdprojects/{proID}")
public BDProject getProject(@PathVariable String proID){
    return bdProjectService.getProject(proID);
}

@RequestMapping(method= RequestMethod.POST, value="/bdusers/{userID}/bdprojects")
public void addProject(@RequestBody BDProject bdProject, @PathVariable String userID){
    bdProject.setBdUser(new BDUser(userID, "", "", ""));
    bdProjectService.addProject(bdProject);
}

@RequestMapping(method= RequestMethod.PUT, value="/bdusers/{userID}/bdprojects/{proID}")
public void updateProject(@RequestBody BDProject bdProject, @PathVariable String userID, @PathVariable String proID){
    bdProject.setBdUser(new BDUser(userID, "", "", ""));
    bdProjectService.updateProject(bdProject);
}

@RequestMapping(method= RequestMethod.DELETE, value="/bdusers/{userID}/bdprojects/{proID}")
public void deleteProject(@PathVariable String proID){
    bdProjectService.deleteProject(proID);
}
@RestController
公共类BDProjectController{
@自动连线
私人BDProjectService BDProjectService;
@请求映射(“/bdusers/{userID}/bdprojects”)
公共列表getAllProjects(@PathVariable String proID){
返回bdProjectService.getAllProjects(proID);
}
@请求映射(“/bdusers/{userID}/bdprojects/{proID}”)
公共BDProject getProject(@PathVariable字符串proID){
返回bdProjectService.getProject(proID);
}
@RequestMapping(method=RequestMethod.POST,value=“/bdusers/{userID}/bdprojects”)
public void addProject(@RequestBody BDProject BDProject,@PathVariable String userID){
setBdUser(新的BDUser(userID,“,”,“);
bdProjectService.addProject(bdProject);
}
@RequestMapping(method=RequestMethod.PUT,value=“/bdusers/{userID}/bdprojects/{proID}”)
public void updateProject(@RequestBody BDProject BDProject,@PathVariable String userID,@PathVariable String proID){
setBdUser(新的BDUser(userID,“,”,“);
bdProjectService.updateProject(bdProject);
}
@RequestMapping(method=RequestMethod.DELETE,value=“/bdusers/{userID}/bdprojects/{proID}”)
public void deleteProject(@PathVariable字符串proID){
bdProjectService.deleteProject(proID);
}
}

服务

@Service
public class BDProjectService {

@Autowired
private BDProjectRepository bdProjectRepository;

public List<BDProject> getAllProjects(String userID){
    List<BDProject> bdProjects = new ArrayList<>();
    bdProjectRepository.findByUserID(userID).forEach(bdProjects::add);
    return bdProjects;
}

public BDProject getProject(String proID){

    return bdProjectRepository.findById(proID).orElse(null);
}

public void addProject(BDProject BDProject){

    bdProjectRepository.save(BDProject);
}

public void updateProject(BDProject BDProject){

    bdProjectRepository.save(BDProject);
}

public void deleteProject(String proID){

    bdProjectRepository.deleteById(proID);
}

}
@服务
公共类BDProjectService{
@自动连线
私有BDProjectRepository BDProjectRepository;
公共列表GetAllProject(字符串用户ID){
List bdProjects=new ArrayList();
bdProjectRepository.findByUserID(userID).forEach(bdProjects::add);
返回项目;
}
公共BDProject getProject(字符串项目ID){
返回bdProjectRepository.findById(proID).orElse(null);
}
公共无效添加项目(BDProject BDProject){
bdProjectRepository.save(BDProject);
}
公共无效更新项目(BDProject BDProject){
bdProjectRepository.save(BDProject);
}
公共项目(字符串项目ID){
bdProjectRepository.deleteById(proID);
}
}
存储库

public interface BDProjectRepository extends CrudRepository<BDProject, String>{

    public List<BDProject> findByUserID(String userID);

}
公共接口BDProjectRepository扩展了Crudepository{
公共列表findByUserID(字符串userID);
}

非常感谢您的任何帮助。谢谢

您已经为BDProject实体创建了BDProjectRepository接口。 请修改该存储库中的方法:

现在:
公共列表findByUserID(字符串userID)

应该是:
公共列表findByProID(字符串proID)

如果要获取特定用户的BDProject,可以通过查询相关对象来检索它


公共列表findByBdUser\u用户id(字符串proID)

当通过引用对象中的字段进行查询时,您应该像编写ChildObject\u ChildID一样编写它

公共接口BDProjectRepository扩展了Crudepository
{
公共列表findByBdUser_UserID(字符串UserID);
}

在BDProject中,您拥有属性

private BDUser bdUser;
在存储库中,您有:

public List<BDProject> findByUserID(String userID);

@jak_taylor123对端点使用GetMapping、PutMapping、PostMapping和DeleteMapping,而不是RequestMapping
public List<BDProject> findByUserID(String userID);
findByUserID(String userID) to findByBdUserUserID(String userID)