【问题标题】:How to update only attributes that have changed - Spring MVC mongoDB如何仅更新已更改的属性 - Spring MVC mongoDB
【发布时间】:2020-09-05 22:42:43
【问题描述】:

我正在使用 Spring Data MongoDB 和 Spring Data Rest 创建一个 REST API,它允许对我的 MongoDB 数据库进行 GET、POST、PUT 和 DELETE 操作,除了更新操作 (PUT) 之外,它都工作正常。仅当我在请求正文中发送完整对象时才有效,否则未在请求中发送的变量为空。有人可以指导我解决这个问题。

@PutMapping("/update/{id}")
    public void update(@Valid @RequestBody Facture facture, @PathVariable("id") String id){
        Optional<Facture> factureData = factureRepository.findById(id);

            facture.setId_facture(id);
            this.factureRepository.save(facture);
}

【问题讨论】:

    标签: mongodb spring-boot api rest spring-data


    【解决方案1】:

    你可以试试像javer这样的对象比较库

    【讨论】:

    • 你的意思是我会比较 Diff diff = javers.compare(Olduser, user);
    • @Kindth 是的,那么您将获得旧值和新值的差异图
    猜你喜欢
    • 2016-05-23
    • 2010-10-27
    • 2018-08-15
    • 2017-07-08
    • 2017-01-05
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    相关资源
    最近更新 更多