spring mvc 使用Optional

        return Optional.ofNullable(brokerRepository.findOne(id))
            .map(broker -> new ResponseEntity<>(
                broker,
                HttpStatus.OK))
            .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));

  

原文地址:https://www.cnblogs.com/feika/p/4465530.html