🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一、概述 JPA基本查询也分为两种,一种是spring data默认已经实现,一种是自定义的简单查询,可以根据方法名来自动生成SQL,也可以通过@Query注解实现复杂的查询; ## 二、查询 ~~~ User findFirstByOrderByLastnameAsc(); User findTopByOrderByAgeDesc(); CardInfo findTopByCardSource(long cardSource); Page queryFirst10ByLastname(String lastname, Pageable pageable); Slice findTop3ByLastname(String lastname, Pageable pageable); List findFirst10ByLastname(String lastname, Sort sort); List findTop10ByLastname(String lastname, Pageable pageable); Optional findOptionalByEmailAddress(EmailAddress emailAddress); long countByUserName(String userName); boolean existsByUserName(String userName); List<SysProxyLog> findByRequestAddrLikeAndRequestBodyLike(String requestAddr, String requestBody); List<CardInfoCandidate> findFirst50000By(Sort sort); ~~~ ![](https://img.kancloud.cn/05/34/0534b9f12c3c69c1ba7397b995ee60b8_904x459.png) 具体可以参考:https://docs.spring.io/spring-data/jdbc/docs/2.2.0/reference/html/#repositories.query-methods.details ## 三、非查询操作 根据方法名来自动生成SQL不仅支持普通查询,也支持删除、统计查询等; 分别对应了find/get/read/query/search/stream、delete、count等; ~~~ Long deleteById(Long id); Long removeById(Long id); ~~~