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 JPA:为什么我的用户列表是空的?_Java_Spring - Fatal编程技术网

Java Spring JPA:为什么我的用户列表是空的?

Java Spring JPA:为什么我的用户列表是空的?,java,spring,Java,Spring,H2表格:用户 | USER_ID | USER_NAME | USER_PASSWORD | USER_RIGHTS | ----------------------------------------------------- | 1 | rooter | 123456 | ROOT | @实体 @吸气剂 @塞特 @表(name=“USERS”) 公共类用户{ @身份证 @GeneratedValue(策略=GenerationT

H2表格:
用户

 | USER_ID | USER_NAME | USER_PASSWORD | USER_RIGHTS |  
 -----------------------------------------------------
 |    1    |  rooter   |     123456    |    ROOT     |  
@实体
@吸气剂
@塞特
@表(name=“USERS”)
公共类用户{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
@列(name=“user\u id”)
私有长用户ID;
@列(name=“user\u name”)
私有字符串用户名;
@列(name=“user\u password”)
私有字符串用户密码;
@列(name=“用户权限”)
私有字符串用户权限;
//等于()和toString()
}
public interface UserRepository扩展了JpaRepository{
用户findByUserName(字符串用户名);
用户findByUserId(长id);
}
@RestController
@请求映射(“/user”)
公共类UsersApi{
私有最终用户存储库用户存储库;
公共UsersApi(UserRepository UserRepository){
this.userRepository=userRepository;
}
@GetMapping(“/test”)
公共列表测试(字符串名称,长id){
列表响应=新建LinkedList();
add(userRepository.findByUserName(name));
add(userRepository.findByUserId(id));
返回响应;
}
}
当我访问
/user/test?name=rooter&id=1
时,它将响应:

[
无效的
{
“用户ID”:1,
“用户名”:“根”,
“用户密码”:“123456”,
“用户权限”:“root用户”
}
]

为什么方法
findByUserName(字符串用户名)
找不到数据?

在响应数组中,id为1的用户的用户名是root,通过用户名查找用户所提供的请求参数是root。因此,我建议您检查用户名是否为root而不是rooter。

为什么查询参数会说rooter?尝试使用root,而不是用户名为“rooter”,我认为@Aykhan是对的,检查json响应中的
id
,用户名为
root
我认为你搞错了root和rooter-表和响应中的内容不同。