org.springframework.web.reactive.function.server.ServerResponse设置响应头

  • 记录一下
java 复制代码
        String host = serverRequest.uri().getHost();
        Consumer<HttpHeaders> headersConsumer = consumer -> {
            consumer.setAccessControlAllowOrigin(host);
            consumer.setAccessControlAllowCredentials(true);
            consumer.set("Access-Control-Allow-Headers","*");
            consumer.set("Access-Control-Allow-Methods", "*");
            consumer.setAccessControlMaxAge(3600);
        };
		ServerResponse.status(HttpStatus.OK).headers(headersConsumer).body(BodyInserters.fromValue(result));

函数式路由匹配,进行响应头的设置。

相关推荐
桦说编程1 小时前
盘点并发集合里那些容易误判的行为
java·后端·性能优化
IT爱学堂2 小时前
java版数据结构和算法+AI算法和技能学习指南
java·开发语言
lv__pf2 小时前
spring之整合mybatis【TL spring 12】
mysql·spring·mybatis
evans在进步2 小时前
LeetCode 394:字符串解码——Java 单栈模拟与嵌套解析详解
java·python·leetcode
m0_547486663 小时前
《Java程序设计与实践 》全套PPT课件2026
java·开发语言
土司大王3 小时前
LeetCode hto100——字母异位词分组
java·算法·leetcode
码匠许师傅4 小时前
【C++ 面试真题】聊聊 C++ 中的 lambda 表达式
java·c++·面试
jason.zeng@15022074 小时前
linux的top命令
java·linux·服务器
QCodingDev4 小时前
Spring AI Alibaba ReAct Agent实战:从Tool Calling到Agent,企业AI复杂业务该如何设计?
java·人工智能·agent·ai编程·spring ai
RainCity4 小时前
Java Swing 自定义组件库分享(十六)
java·笔记·后端