JPA模糊查询(表中的某些数据)
生活随笔
收集整理的這篇文章主要介紹了
JPA模糊查询(表中的某些数据)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
業務代碼
Controller
@GetMapping({"/task/project"})public ResponseEntity findByProjectTitle(@RequestParam(required = false, defaultValue = "") String title) {return ResponseEntity.ok(projectService.findAllByUserPidAndProjectTitleLikeAndVersionIs(getOperatorId(), title));}Service
@Transactional(readOnly = true)public List<ProjectInfoRepository.ProjectSimpleInfo> findAllByUserPidAndProjectTitleLikeAndVersionIs(String operatorId, String title) {title = StringUtils.hasText(title) ? "%" + title + "%" : "%%";return repository.findAllByUserPidAndProjectTitleLikeAndVersionIs(operatorId, title, 3, ProjectInfoRepository.ProjectSimpleInfo.class);}ProjectRepository
public interface ProjectInfoRepository extends JpaRepository<ProjectInfo, String>, JpaSpecificationExecutor<ProjectInfo>, ProjectInfoCustomRepository {<T> List<T> findAllByUserPidAndProjectTitleLikeAndVersionIs(String userPid, String projectTitle, Integer version, Class<T> type);Optional<ProjectInfo> findByPid(String pid);interface ProjectSimpleInfo {String getPid();String getProjectTitle();} }Repository
<T> List<T> findAllByUserPidAndProjectTitleLikeAndVersionIs(String userPid, String projectTitle, Integer version, Class<T> type); 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的JPA模糊查询(表中的某些数据)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JPA查找数据库最新一条消息
- 下一篇: Uncaught SyntaxError