pid:指导记录主键user_pid:用户主键competition_project_pid:用户作品
/** * 指导记录 * @date 2020/3/24 9:26 */@Repositorypublic interface CompetitionProjectGuideRepository extends JpaRepository<CompetitionProjectGuide, String> { Optional<CompetitionProjectGuide> findFirstByCompetitionProjectPidOrderByUpdateAtDesc(Long pid);}
public Optional<CompetitionProjectGuide> findFirstByCompetitionProjectPidOrderByUpdateAtDesc(Long pid) { return repository.findFirstByCompetitionProjectPidOrderByUpdateAtDesc(pid); }
@RequestMapping(method = {RequestMethod.GET}, value = "/task/project/guide") public ResponseEntity getGuide(Long pid) { Optional<CompetitionProjectGuide> guide = competitionProjectGuideService.findFirstByCompetitionProjectPidOrderByUpdateAtDesc(pid); guide.orElseThrow(() -> new BusinessException( HttpStatus.BAD_REQUEST, Translator.toLocale("guide.NotExists.message"))); return ResponseEntity.ok(guide); }
可以通过findFirst或者findTop来获取