提交 05c98639 编写于 作者: LKJKJOIUIU's avatar LKJKJOIUIU

查询评论接口完善

上级 0f8843bb
......@@ -3,6 +3,7 @@ package com.nav.controller;
import com.nav.common.api.CommonResult;
import com.nav.pojo.Comment;
import com.nav.service.PostService;
import com.nav.vo.result.CommentResult;
import com.nav.vo.result.LifePostResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
......@@ -10,7 +11,9 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 类说明
......@@ -50,8 +53,12 @@ public class PostController {
}
@GetMapping("comment/{id}")
public List<Comment> getCommentByPostId(@PathVariable long id) {
return postService.getCommentByPostId(id);
public Map<Integer,CommonResult> getCommentByPostId(@PathVariable long id) {
Map<Integer,CommonResult> map=new HashMap<>();
CommonResult commonResult=postService.getCommentByPostId(id);
List<CommentResult> commentResult = (List<CommentResult>) commonResult.getData();
map.put(commentResult.size(),commonResult);
return map;
}
}
......@@ -67,5 +67,5 @@ public interface PostService {
* @param id:文章id
* @return:java.util.List<com.nav.pojo.Comment>
**/
public List<Comment> getCommentByPostId(long id);
public CommonResult getCommentByPostId(long id);
}
......@@ -49,7 +49,7 @@ public class PostServiceImpl implements PostService{
}
@Override
public List<Comment> getCommentByPostId(long id) {
return commentDao.selectCommentByPostId(id);
public CommonResult getCommentByPostId(long id) {
return CommonResult.success(commentDao.selectCommentByPostId(id),"请求成功");
}
}
package com.nav.vo.result;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 类说明
* 根据文章id返回的评论内容以及评论者数据集
* @author zyx
* @date 2022/4/29 20:33
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommentResult {
private long id;
private long fromUserId;
private long toPostId;
private long parentId;
private String commentContent;
private String nickname;
private String profilePicture;
private Date gmtCreate;
}
......@@ -3,10 +3,12 @@
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nav.dao.CommentDao">
<select id="selectCommentByPostId" parameterType="long" resultType="com.nav.pojo.Comment">
select *
from comment
where to_post_id = #{id};
<select id="selectCommentByPostId" parameterType="long" resultType="com.nav.vo.result.CommentResult">
select u.nickname,u.profile_picture,c.gmt_create,c.id,c.from_user_id,c.to_post_id,c.parent_id,c.comment_content
from comment c
left join user u
on c.from_user_id = u.id
where c.to_post_id = #{id};
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册