Example
package com.example.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
//annotation exposes the
@RepositoryRestResource(path="/person")
public interface PersonRepository extends JpaRepository<Person,Long> {
//the method below allows us to expose a search query, customize the endpoint name, and specify a parameter name
//the exposed URL is GET /person/search/byLastName?lastname=
@RestResource(path="/byLastName")
Iterable<Person> findByLastName(@Param("lastName") String lastName);
//the methods below are examples on to prevent an operation from being exposed.
//For example DELETE; the methods are overridden and then annotated with RestResouce(exported=false) to make sure that no one can DELETE entities via REST
@Override
@RestResource(exported=false)
default void delete(Long id) { }
@Override
@RestResource(exported=false)
default void delete(Person entity) { }
@Override
@RestResource(exported=false)
default void delete(Iterable<? extends Person> entities) { }
@Override
@RestResource(exported=false)
default void deleteAll() { }
@Override
@RestResource(exported=false)
default void deleteAllInBatch() { }
@Override
@RestResource(exported=false)
default void deleteInBatch(Iterable<Person> arg0) { }
}