作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
新手问题...我正在构建我的第一个 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/
我是一名优秀的程序员,十分优秀!