这篇文章上次修改于 2234 天前,可能其部分内容已经发生变化,如有疑问可询问作者。 ### webflux的mvc中添加cookie,和spring mvc 不太一样,需要再controller中的方法中加入ServerWebExchange exchange 参数,如下: ```java @RequestMapping("admin/login") public CommonResult login(@RequestBody AdminLoginForm adminLoginForm, @ApiIgnore ServerWebExchange exchange) { CommonResult result = CommonResult.getInstance(); if (checkAuth(adminLoginForm)) { ResponseCookie responseCookie = ResponseCookie.from("token", loginRecord.getToken()).build(); exchange.getResponse().addCookie(responseCookie); AdminLoginResponseData responseData = AdminLoginResponseData.ofAdmin(); result.setData(responseData); } return result; } ``` ###其中的关键代码 ```java ResponseCookie responseCookie = ResponseCookie.from("token", loginRecord.getToken()).build(); exchange.getResponse().addCookie(responseCookie); ```
没有评论