[英]spring boot jpa repository interface always returns null
即使我传递了一个有效的密钥,这在我的控制器中也仍然在我下面的代码中,因此结果总是为null。有人可以告诉我为什么会这样。以下是我的存储库,控制器和域类
public interface AbcRepository extends JpaRepository<ForgotPasswordToken, int> {
Abc findByHashKey(String hashKey);
Abc findByUser(User user);
}
对应:
@RequestMapping(value = "/validateKey/{hashKey}", method = RequestMethod.GET)
public ResponseEntity validateKey(@PathVariable String hashKey) {
Abc abc = AbcRepository.findByHashKey(hashKey);
if (abc == null) {
return ResponseEntity.badRequest().body("Invalid key");
}
return ResponseEntity.ok().body(abc.getUser());
}
实体:
@Entity
@Data
public class Abc {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
private User user;
private String hashKey;
private String email;
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@PrePersist
public void onCreate() {
this.createdAt = new Date();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.