diff --git a/flower_back/src/main/java/com/example/flower/controller/CommentController.java b/flower_back/src/main/java/com/example/flower/controller/CommentController.java new file mode 100644 index 0000000..f7d4036 --- /dev/null +++ b/flower_back/src/main/java/com/example/flower/controller/CommentController.java @@ -0,0 +1,89 @@ +package com.example.flower.controller; + +import com.alibaba.fastjson.JSONObject; +import com.example.flower.entity.Comment; +import com.example.flower.service.CommentService; +import com.example.flower.unit.JWTUtil; +import io.jsonwebtoken.Claims; +import jakarta.annotation.Resource; +import org.springframework.web.bind.annotation.*; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +@RestController +@RequestMapping("/comment") +public class CommentController { + @Resource + private CommentService commentService; + + @PostMapping("/list") //commentList获取所有评论列表 + public JSONObject commentList(@RequestHeader String Authorization, @RequestBody JSONObject param){ + JSONObject jsonObject = new JSONObject(); + + if(!JWTUtil.checkToken(Authorization)){ //token认证失败 + JWTUtil.checkTokenFailed(jsonObject); + return jsonObject; + } + JSONObject jsonObject1 = new JSONObject(); + int page=param.getIntValue("page"); + int page_size=param.getIntValue("page_size"); + int flower_id=param.getIntValue("flower_id"); + + List commentList = commentService.commentList(page,page_size,flower_id).getList(); + + jsonObject1.put("page_number",commentService.commentList(page,page_size,flower_id).getPages()); + jsonObject1.put("total",commentService.commentList(page,page_size,flower_id).getTotal()); + + int size=commentList.size(); + + JSONObject[] objects = new JSONObject[size]; + for(int i = 0;i