2017-08-08 59 views
1

我如何可以結合兩種不同的responseEntity並返回如何結合2 responseEntity和返回?

public ResponseEntity<?> getObject(@PathVariable("shopId") String shopId, 
      @PathVariable("delearId") String delearId) { 
     Shop objectToSave = (shopId.equalsIgnoreCase("0")) ? (null) : shopService.findOne(shopId); 
     Delear objectName = (delearId.equalsIgnoreCase("0")) ? null : delearService.findOne(delearId); 
     ResponseEntity<?> responseEntity = new ResponseEntity<>(objectName && objectToSave , HttpStatus.OK);// i want to combine both delear and shop 

     if (objectName == null && objectToSave == null) { 
     responseEntity = new ResponseEntity<>(objectName,objectToSave , HttpStatus.NOT_FOUND); 
    } 
    return responseEntity; 
    } 
+0

將它們組合成一個DTO – Optio

回答

0

您可以DTO類響應:

public class ResponseDto { 

    private Shop shop; 

    private Delear delear; 

    // getters and setters 
} 

然後

ResponseDto response = new ResponseDto(); 
response.setShop(shop); 
response.setDelear(delear); 

然後讓你的方法public ResponseEntity<ResponseDto> getObject ... and return new ResponseEntity<>(response, HttpStatus.OK);

相關問題