From 86666ff044349110ff3a2e62c2423b900efe9281 Mon Sep 17 00:00:00 2001 From: hanserwei Date: Wed, 22 Oct 2025 16:34:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(dashscope):=20=E6=94=AF=E6=8C=81=E8=B7=A8?= =?UTF-8?q?=E5=9F=9F=E5=B9=B6=E4=BF=AE=E6=94=B9=E8=81=8A=E5=A4=A9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=B8=BAPOST=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了@CrossOrigin注解以支持跨域访问 - 将/chat接口从GET请求改为POST请求- 修改请求参数接收方式为@RequestBody - 移除了不必要的导入语句 --- .../snailsai/controller/DashScopeController.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hanserwei/snailsai/controller/DashScopeController.java b/src/main/java/com/hanserwei/snailsai/controller/DashScopeController.java index 21bb4b5..5155de4 100644 --- a/src/main/java/com/hanserwei/snailsai/controller/DashScopeController.java +++ b/src/main/java/com/hanserwei/snailsai/controller/DashScopeController.java @@ -3,21 +3,19 @@ package com.hanserwei.snailsai.controller; import jakarta.annotation.Resource; import org.springframework.ai.chat.client.ChatClient; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Flux; @RequestMapping("/dashscope") @RestController +@CrossOrigin public class DashScopeController { @Resource private ChatClient dashScopeChatClient; - @GetMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE) - public Flux chat(@RequestParam("userPrompt") String userPrompt) { + @PostMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE) + public Flux chat(@RequestBody String userPrompt) { return dashScopeChatClient.prompt() .user(userPrompt) .stream()