新手问题...我正在构建我的第一个 Spring Boot Restful 服务。我的 Restful 服务设计需要在响应 header 中返回一些数据。
如何在我的 Controller 类方法中设置响应 header 值?
最佳答案
来自 Spring 文档:
@RequestMapping("/handle")
public ResponseEntity<String> handle() {
URI location = ...;
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setLocation(location);
responseHeaders.set("MyResponseHeader", "MyValue");
return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
}
来源:https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/ResponseEntity.html
关于spring - 如何在 Spring Boot 休息服务方法中设置响应 header value ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45152484/