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