相关疑难解决方法(0)

为什么不允许HTTP PUT在REST API中进行部分更新?

谁说RESTful API必须通过HTTP PATCH单独支持部分更新?

它似乎没有任何好处.它增加了在服务器端实现的更多工作,以及客户端的更多逻辑,以决定请求哪种更新.

我在使用HTTP创建REST API的上下文中提出这个问题,该API为已知数据模型提供抽象.需要PATCH进行部分更新而不是PUT的全部或部分感觉它没有任何好处,但我可以被说服.

有关

http://restcookbook.com/HTTP%20Methods/idempotency/ - 这意味着您无法控制可能缓存请求的服务器软件.

不允许部分PUT背后的理由是什么? - 没有明确的答案,只提到HTTP为PUt和PATCH定义的内容.

http://groups.yahoo.com/neo/groups/rest-discuss/conversations/topics/17415 - 显示了对此的分歧.

api rest http

36
推荐指数
2
解决办法
2万
查看次数

如何区分Spring Rest Controller中部分更新的null值和未提供值

我试图在Spring Rest Controller中使用PUT请求方法部分更新实体时,区分空值和未提供的值.

以下面的实体为例:

@Entity
private class Person {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /* let's assume the following attributes may be null */
    private String firstName;
    private String lastName;

    /* getters and setters ... */
}
Run Code Online (Sandbox Code Playgroud)

我的人员库(Spring Data):

@Repository
public interface PersonRepository extends CrudRepository<Person, Long> {
}
Run Code Online (Sandbox Code Playgroud)

我使用的DTO:

private class PersonDTO {
    private String firstName;
    private String lastName;

    /* getters and setters ... */
}
Run Code Online (Sandbox Code Playgroud)

我的Spring RestController:

@RestController
@RequestMapping("/api/people")
public class PersonController {

    @Autowired
    private PersonRepository people; …
Run Code Online (Sandbox Code Playgroud)

java rest json spring-mvc jackson

27
推荐指数
4
解决办法
5211
查看次数

标签 统计

rest ×2

api ×1

http ×1

jackson ×1

java ×1

json ×1

spring-mvc ×1