增加 Utf8SseEmitter 处理 中文乱码问题

This commit is contained in:
cherishsince 2024-04-14 15:51:57 +08:00
parent 8b310c1dce
commit 4b5910f972
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.ai.controller;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.nio.charset.StandardCharsets;
/**
* 解决中文乱码
*
* @author fansili
* @time 2024/4/14 15:13
* @since 1.0
*/
public class Utf8SseEmitter extends SseEmitter {
@Override
protected void extendResponse(ServerHttpResponse outputMessage) {
super.extendResponse(outputMessage);
HttpHeaders headers = outputMessage.getHeaders();
headers.setContentType(new MediaType(MediaType.TEXT_EVENT_STREAM, StandardCharsets.UTF_8));
}
}