我在文档(https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation)中找不到具体信息,并且在多个博客中也没有找到满意的答案,所以我有一个问题。
我有一个名为Entity的表:
@Entity
@Table(name = "workstation")
public class Workstation
{
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userid", nullable = false)
public User user;
}
并且用户表实体:
public class user
{
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID", unique = true, nullable = false)
public Integer id;
@Column(name = "age", nullable = false)
public int age
}
现在我想要在我的代码库中运行以下这样的查询:
public interface WorkstationRepo extends CrudRepository<Workstation, Long> {
findByUserAgeLesserThan(int maxAge);
}
我希望通过我的工作站实体找到所有年龄在一定范围内的用户。
是否可以不使用@Query注解来完成?如果可以,应该怎么编写?
@Query()
。 - Abdullah Khan