How to distinguish between null and not provided values for partial updates in Spring Rest Controller

后端 未结 7 855
囚心锁ツ
囚心锁ツ 2020-12-04 17:32

I\'m trying to distinguish between null values and not provided values when partially updating an entity with PUT request method in Spring Rest Controller.

Consider

7条回答
  •  广开言路
    2020-12-04 18:17

    Probably to late but following code works for me to distinguish between null and not provided values

    if(dto.getIban() == null){
      log.info("Iban value is not provided");
    }else if(dto.getIban().orElse(null) == null){
      log.info("Iban is provided and has null value");
    }else{
      log.info("Iban value is : " + dto.getIban().get());
    }
    

提交回复
热议问题