CommentMapper.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. package cn.seecoder.fdroidrepository.Mapper;
  2. import cn.seecoder.fdroidrepository.DataObject.Comment;
  3. import cn.seecoder.fdroidrepository.Service.CommentService;
  4. import org.apache.ibatis.annotations.*;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.http.HttpStatus;
  7. import org.springframework.http.ResponseEntity;
  8. import org.springframework.web.bind.annotation.*;
  9. import java.util.List;
  10. // CommentController.java
  11. // CommentMapper.java
  12. @Mapper
  13. public interface CommentMapper {
  14. @Select("SELECT * FROM comments WHERE post_id = #{postId}")
  15. @Results({
  16. @Result(property = "commentId", column = "comment_id"),
  17. @Result(property = "postId", column = "post_id"),
  18. @Result(property = "userId", column = "user_id"),
  19. @Result(property = "content", column = "content"),
  20. @Result(property = "createdAt", column = "created_at")
  21. // 添加其他属性映射关系
  22. })
  23. List<Comment> findByPostId(Long postId);
  24. @Insert("INSERT INTO comments (post_id, user_id, content, created_at) " +
  25. "VALUES (#{postId}, #{userId}, #{content}, #{createdAt})")
  26. void save(Comment comment);
  27. }