PostsCommentsMapper.xml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.sumbytes.helloblog.posts.dao.PostsCommentsDao">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.sumbytes.helloblog.posts.domain.po.PostsComments">
  6. <id column="id" property="id"/>
  7. <result column="create_time" property="createTime"/>
  8. <result column="author_id" property="authorId"/>
  9. <result column="content" property="content"/>
  10. <result column="parent_id" property="parentId"/>
  11. <result column="status" property="status"/>
  12. <result column="posts_id" property="postsId"/>
  13. <result column="tree_path" property="treePath"/>
  14. </resultMap>
  15. <select id="selectPostsCommentsByPostsIdList" resultType="com.sumbytes.helloblog.posts.domain.vo.PostsCommentsVO">
  16. SELECT
  17. postsComments.id,
  18. postsComments.content,
  19. postsComments.create_time createTime,
  20. authUser.name authorName,
  21. authUser.avatar authorAvatar,
  22. parentAuthUser.name parentUserName
  23. FROM
  24. hello_blog_posts_comments postsComments
  25. LEFT JOIN hello_blog_auth_user authUser ON postsComments.author_id = authUser.id
  26. LEFT JOIN hello_blog_posts_comments parentPostsComments ON postsComments.parent_id = parentPostsComments.id
  27. LEFT JOIN hello_blog_auth_user parentAuthUser ON parentAuthUser.id = ( SELECT author_id FROM hello_blog_posts_comments WHERE id = postsComments.parent_id )
  28. <where>
  29. postsComments.posts_id = #{postsId}
  30. </where>
  31. ORDER BY postsComments.id DESC
  32. </select>
  33. <select id="selectPostsCommentsList" resultType="com.sumbytes.helloblog.posts.domain.vo.PostsCommentsVO">
  34. SELECT
  35. postsComments.id as id,
  36. postsComments.content,
  37. authUser.name as authorName,
  38. authUser.avatar as authorAvatar,
  39. parentAuthUser.name as parentUserName,
  40. posts.title as postTitle
  41. FROM
  42. hello_blog_posts_comments postsComments
  43. LEFT JOIN hello_blog_auth_user authUser ON postsComments.author_id = authUser.id
  44. LEFT JOIN hello_blog_posts_comments parentPostsComments ON postsComments.id = parentPostsComments.parent_id
  45. LEFT JOIN hello_blog_auth_user parentAuthUser ON parentAuthUser.id = ( SELECT author_id FROM hello_blog_posts_comments WHERE id = postsComments.parent_id )
  46. LEFT JOIN hello_blog_posts posts ON posts.id = postsComments.posts_id
  47. <where>
  48. <if test="postsComments.keywords != null and postsComments.keywords != ''">
  49. ( postsComments.content LIKE #{postsComments.keywords} OR posts.title LIKE #{postsComments.keywords} )
  50. </if>
  51. <if test="postsComments.id!=null">
  52. and postsComments.id=#{postsComments.id}
  53. </if>
  54. </where>
  55. ORDER BY postsComments.id DESC
  56. </select>
  57. </mapper>