我想从我的表中找到我使用JPArepository
的独特员工public List<String> findDistinctempName();
我将服务器启动异常作为
No property findDistinctempName found for type Employee !
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:79) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:335) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:311) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:274) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:245) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:247) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:378) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:86) ~[spring-data-commons-1.13.11.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:70) ~[spring-data-jpa-1.11.11.RELEASE.jar:na]
... 52 common frames omitted
任何人都可以建议我找到一个表的唯一行,具有不同的empName和手机号
答案 0 :(得分:1)
您需要使用by
findDistinctByEmpName();
答案 1 :(得分:0)
您无法使用findBy获取不同的记录...您需要创建自定义查询以获得所需结果。您可以使用group by获取唯一记录。请在下面找到存储库代码,按名称和ID获取所有汽车组。
public interface CarRepository extends JpaRepository<Car, Integer>, JpaSpecificationExecutor {
@Query("select car from Car car group by car.name,car.id")
List<Car> findDistinctByName();
}
@Entity
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "car_id")
int car_id;
String name;
}