Like 쿼리 예제

많은 간단한 LIKE 쿼리 시나리오의 경우 다양한 키워드를 활용하여 리포지토리에서 쿼리 메서드를 만들 수 있다.

 

NoticeRepository.js

 

List<Object> findAllByTitleContaining(String title);
List<Notice> findAllByTitleContains(String title);
List<Notice> findByTitleIsContaining(String title);

 

NoticeController.js

@GetMapping("/api/category/{category}")
public Object category(@PathVariable String category){
    return noticeService.category(category);
}

NoticeService.js

    @Transactional
    public  Object category(String category){
        return noticeRepository.findAllByTitleContains(category);
    }
}

http://localhost:8080/api/category/game 입력

결과:

    {
        "createdAt""2022-10-05T19:17:35.303884",
        "modifiedAt""2022-10-05T19:17:35.303884",
        "id"68,
        "title""game",
        "writer""jossi",
        "content""게임을 합시다."
    },

'항해 99(9기) > 항해 일일' 카테고리의 다른 글

항해 99 19일차  (1) 2022.10.07
항해 99 18일차  (0) 2022.10.06
항해 99 16일차  (0) 2022.10.04
항해 99 15일차  (0) 2022.10.03
항해 99 13일 차  (0) 2022.10.01

+ Recent posts