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

 

相关文章:

  • 2021-08-21
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-11-29
  • 2021-12-04
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2021-05-27
  • 2021-09-18
  • 2022-12-23
  • 2021-05-27
  • 2021-07-15
  • 2021-12-12
相关资源
相似解决方案