首页 > 编程语言 > 详细

springboot rest 配置

时间:2019-08-29 20:20:21      阅读:248      评论:0      收藏:0      [点我收藏+]

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

 

springboot rest 配置

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!