springboot rest 配置

匿名 (未验证) 提交于 2019-12-02 23:56:01

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!