Spring Security登陆只显示自己信息
把Authentication(认证)作为参数,通过认证信息获取用户的姓名,然后通过姓名去数据库查找
@RequestMapping(value = "/users")
@ResponseBody
public List<Student> getAll(Authentication authentication){
String sname = authentication.getName(); //通过认证信息获取学生的姓名
List<Student> users = userRepository.findByUsername(sname);
return users;
}