ITPub博客

首页 > 架构设计 > > 什么是 Spring Date REST

什么是 Spring Date REST

作者:gung123 时间:2020-02-27 16:11:45 0 删除 编辑

Spring Date TEST 可以用来发布关于 Spring 数据库的 HATEOAS RESTful 资源。

下面是一个使用 JPA 的例子

@RepositoryRestResource(collectionResourceRel = "todos", path = "todos")
public interface TodoRepository
extends PagingAndSortingRepository<Todo, Long> {

不需要写太多代码,我们可以发布关于 Spring 数据库的 RESTful API。

下面展示的是一些关于 TEST 服务器的例子

POST

  • URL:http://localhost:8080/todos

  • Use Header:Content-Type:Type:application/json

  • Request Content

  • 代码如下 

{
 "user": "Jill",
 "desc": "Learn Hibernate",
  "done": false
}

  • 响应内容 

{
"user": "Jill",
"desc": "Learn Hibernate",
"done": false,
"_links": {
"self": {
"href": "http://localhost:8080/todos/1"
},
"todo": {
"href": "http://localhost:8080/todos/1"
}
}
}

响应包含新创建资源的 href。 欢迎大家加我qq:1038774626探讨技术问题。


欢迎大家加我qq:1038774626探讨技术问题。


欢迎大家加我qq:1038774626探讨技术问题。 


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69952307/viewspace-3145836/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-11-01

  • 博文量
    200
  • 访问量
    79622