Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何将2个响应和返回结合起来?_Spring_Spring Mvc - Fatal编程技术网

Spring 如何将2个响应和返回结合起来?

Spring 如何将2个响应和返回结合起来?,spring,spring-mvc,Spring,Spring Mvc,我如何将两种不同的响应结合起来 public ResponseEntity<?> getObject(@PathVariable("shopId") String shopId, @PathVariable("delearId") String delearId) { Shop objectToSave = (shopId.equalsIgnoreCase("0")) ? (null) : shopService.findOne(shopId)

我如何将两种不同的响应结合起来

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;
    }
public ResponseEntity getObject(@PathVariable(“shopId”)字符串shopId,
@PathVariable(“delerad”)字符串(delerad){
Shop objectToSave=(shopId.equalsIgnoreCase(“0”)?(null):shopService.findOne(shopId);
Delear objectName=(deleard.equalsIgnoreCase(“0”)?null:delearService.findOne(deleard);
ResponseEntity ResponseEntity=newresponseEntity(objectName&&objectToSave,HttpStatus.OK);//我想合并delear和shop
if(objectName==null&&objectToSave==null){
responseEntity=新的responseEntity(objectName、objectToSave、HttpStatus.NOT_FOUND);
}
返回响应性;
}

您可以将DTO类设置为响应:

public class ResponseDto {

   private Shop shop;

   private Delear delear;

   // getters and setters
}
然后

然后使您的方法
公开响应EntityGetObject
。。。
返回新的ResponseEntity(response,HttpStatus.OK)

您可以将DTO类设置为响应:

public class ResponseDto {

   private Shop shop;

   private Delear delear;

   // getters and setters
}
然后

然后使您的方法
公开响应EntityGetObject
。。。
返回新的ResponseEntity(response,HttpStatus.OK)

将它们组合成一个数据O将它们组合成一个数据O