springboot rest 配置

spring boot 定义rest资源

1.引入起步依赖

implementation 'org.springframework.boot:spring-boot-starter-data-rest'

2.定义实体bean

3.访问rest资源

http://localhost:8080/xxxxs

自定义rest方法

@RestResource(path = "start",rel = "nameStartWith")
Person findByNameStartsWith(@Param("name")String name);

search访问

http://localhost:8080/persons/search/start?name=xxx

分页

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

原文地址:https://www.cnblogs.com/jony-it/p/11431639.html