| | |
| | | import cn.lili.group.Update; |
| | | import cn.lili.group.Add; |
| | | import cn.lili.modules.lmk.domain.form.ThumbsUpRecordForm; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import lombok.RequiredArgsConstructor; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | public class VideoCommentController { |
| | | |
| | | private final VideoCommentService videoCommentService; |
| | | |
| | | // Jackson 实例(用于手动解析 JSON) |
| | | private final ObjectMapper objectMapper = new ObjectMapper(); |
| | | @PostMapping("/thumbs_up") |
| | | @ApiOperation(value = "点赞评论", notes = "点赞评论") |
| | | public Result thumbsUp(@RequestBody @Validated(Add.class) ThumbsUpRecordForm form) { |
| | |
| | | return videoCommentService.cancelThumbsUp(form); |
| | | } |
| | | |
| | | // @PostMapping("/comment") |
| | | // @ApiOperation(value = "评论", notes = "评论") |
| | | // public Result comment(@RequestBody @Validated(Add.class) VideoCommentForm form) { |
| | | // System.out.println("打印出:" + form.getCommentContent()); |
| | | // String content = EmojiParser.parseToAliases(form.getCommentContent()); |
| | | // System.out.println("解析后:" + content); |
| | | // return videoCommentService.comment(form); |
| | | // } |
| | | |
| | | @PostMapping("/comment") |
| | | @ApiOperation(value = "评论", notes = "评论") |
| | | public Result comment(@RequestBody @Validated(Add.class) VideoCommentForm form) { |
| | | public Result comment(HttpServletRequest request)throws IOException { |
| | | BufferedReader reader = request.getReader(); |
| | | StringBuilder jsonStr = new StringBuilder(); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | jsonStr.append(line); |
| | | } |
| | | String requestBody = jsonStr.toString(); |
| | | System.out.println("后端接收的 JSON 字符串:" + requestBody); |
| | | // 正常输出:{"commentContent":"我\uD83E\uDD26\u200D\u2642\uFE0F...",...} |
| | | |
| | | // 2. 手动解析 JSON 字符串(显式使用 UTF-8 编码) |
| | | VideoCommentForm form = objectMapper.readValue( |
| | | requestBody.getBytes(StandardCharsets.UTF_8), // 转为 UTF-8 字节数组 |
| | | VideoCommentForm.class // 目标实体类 |
| | | ); |
| | | |
| | | return videoCommentService.comment(form); |
| | | } |
| | | |