liubao68 commented on issue #1522: 接口返回值定义的是ResponseEntity,为什么返回值的Body为空?
URL: 
https://github.com/apache/servicecomb-java-chassis/issues/1522#issuecomment-575428095
 
 
   下面有个例子可以参考下:
   
   ```
     @ResponseHeaders({@ResponseHeader(name = "h1", response = String.class),
         @ResponseHeader(name = "h2", response = String.class)})
     @RequestMapping(path = "/responseEntity", method = RequestMethod.POST)
     public ResponseEntity<Date> responseEntity(InvocationContext c1, 
@RequestAttribute("date") Date date) {
       HttpHeaders headers = new HttpHeaders();
       headers.add("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE));
   
       InvocationContext c2 = ContextUtils.getInvocationContext();
       headers.add("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE));
   
       return new ResponseEntity<>(date, headers, HttpStatus.ACCEPTED);
     }
   ```
   
   注意:
   1. 需要显示声明ResponseEntity的模板类型;
   2. 如果还需要返回额外的headers,需要通过ResponseHeaders显示的声明返回的header。 
   
   这个是java-chassis和Spring MVC不同的地方, 接口定义需要是明确的,能够通过契约描述出来实际的类型和header。 
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to