业务代码
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);
}
此方法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);