spring mvc 使用Optional

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

  

posted @ 2015-04-29 11:42  samu  阅读(726)  评论(1编辑  收藏  举报