spring mvc 使用Optional

        return Optional.ofNullable(brokerRepository.findOne(id))

            .map(broker -> new ResponseEntity<>(

                broker,

                HttpStatus.OK))

            .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));

  

你可能感兴趣的:(spring mvc)