Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Методички / spring_lab4.pdf
Скачиваний:
0
Добавлен:
28.06.2026
Размер:
111.26 Кб
Скачать

PUT http://localhost:8080/notifications/{id}

DELETE http://localhost:8080/notifications/{id}

GET http://localhost:8080/notifications/status/{status}

GET http://localhost:8080/notifications/channel/{channel}

GET http://localhost:8080/notifications/recipient/{recipientId}

Пример JSON для создания уведомления:

{

"title": "Напоминание",

"message": "Завтра состоится занятие по Spring Data", "channel": "EMAIL",

"recipientId": 1

}

Часть 6. Методы репозитория Spring Data JPA

6.1. Запрос по нескольким параметрам

Добавьте в NotificationRepository :

List<Notification> findByStatusAndChannel(NotificationStatus status, NotificationChannel channel);

Spring Data JPA умеет разбирать имя метода и строить запрос по свойствам сущности и ключевым словам And , Or , After , Between , Like , OrderBy и другим.

6.2. Сортировка в имени метода

List<Notification> findByStatusOrderByCreatedAtAsc(NotificationStatus status);

Spring Data JPA поддерживает статическую сортировку через OrderBy...Asc и OrderBy...Desc в имени метода.

6.3. Использование @Query

JPQL-запрос:

@Query("""

select n

from Notification n where n.status = :status

and n.channel = :channel

""")

List<Notification> findByStatusAndChannelCustom(@Param("status") NotificationStatus status,

17

Соседние файлы в папке Методички