spring boot 定義rest資源spring
1.引入起步依賴api
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
2.定義實體beanspring-boot
3.訪問rest資源post
http://localhost:8080/xxxxs測試
自定義rest方法spa
@RestResource(path = "start",rel = "nameStartWith")
Person findByNameStartsWith(@Param("name")String name);
search訪問rest
http://localhost:8080/persons/search/start?name=xxxcode
分頁blog
http://localhost:8080/persons/?page=0&size=20&sort=age,desc,name,asc資源
使用postman測試保存、更新
保存save
發起POST方法
更新發起PUT 方法
刪除發起DELETE方法
定製:
1.根路徑:properties 配置
spring.data.rest.base-path=/api
訪問
http://localhost:8080/api/persons
2.定製節點路徑
spring data rest 默認規則:實體類後加「s」造成路徑。
定製節點路徑,在repo 下使用restResource 註解
@RepositoryRestResource(path = "people") public interface IPersonRepository extends CustomRepo<Person,String>
訪問
http://localhost:8080/api/people