Files
guidance-backend/community-8073/src/main/resources/mapper/PostMapper.xml
2024-08-13 14:02:11 +08:00

85 lines
3.5 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ivmiku.tutorial.mapper.PostMapper">
<resultMap id="BaseResultMap" type="com.ivmiku.tutorial.entity.Post">
<id property="postId" column="post_id" jdbcType="BIGINT"/>
<result property="userOpenid" column="user_openid" jdbcType="VARCHAR"/>
<result property="communityId" column="community_id" jdbcType="BIGINT"/>
<result property="title" column="title" jdbcType="VARCHAR"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="videoUrl" column="video_url" jdbcType="VARCHAR"/>
<result property="imageUrls" column="image_urls" jdbcType="VARCHAR"/>
<result property="isDeleted" column="is_deleted" jdbcType="TINYINT"/>
<result property="isOfficial" column="is_official" jdbcType="TINYINT"/>
<result property="isPublic" column="is_public" jdbcType="TINYINT"/>
<result property="location" column="location" jdbcType="VARCHAR"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
post_id, user_openid, community_id, title, content,
video_url, image_urls,
is_deleted, is_official, is_public, location, created_at, updated_at
</sql>
<!-- 查询指定帖子的所有评论 -->
<select id="selectCommentsByPostId" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM post
WHERE post_id = #{postId} AND is_deleted = 0
</select>
<!-- 插入新的帖子 -->
<insert id="insertPost" parameterType="com.ivmiku.tutorial.entity.Post">
INSERT INTO post (
post_id, user_openid, community_id, title, content,
video_url, image_urls,
is_deleted, is_official, is_public, location, created_at, updated_at
) VALUES (
#{postId}, #{userOpenid}, #{communityId}, #{title}, #{content},
#{videoUrl}, #{imageUrls},
#{isDeleted}, #{isOfficial}, #{is_public}, #{location}, #{createdAt}, #{updatedAt}
)
</insert>
<!-- 更新帖子 -->
<update id="updatePost" parameterType="com.ivmiku.tutorial.entity.Post">
UPDATE post
SET
user_openid = #{userOpenid},
community_id = #{communityId},
title = #{title},
content = #{content},
video_url = #{videoUrl},
image_urls = #{imageUrls},
is_deleted = #{isDeleted},
is_official = #{isOfficial},
is_public = #{is_public},
location = #{location},
created_at = #{createdAt},
updated_at = #{updatedAt}
WHERE post_id = #{postId}
</update>
<!-- 删除帖子实际上是将is_deleted字段设置为1 -->
<update id="deletePost">
UPDATE post
SET is_deleted = 1, updated_at = CURRENT_TIMESTAMP
WHERE post_id = #{postId}
</update>
<select id="getTagPostList" resultType="com.ivmiku.tutorial.entity.Post">
SELECT p.post_id, p.user_openid, p.community_id, p.title, p.content,
p.is_deleted, p.is_official, p.is_public, p.location, p.created_at, p.updated_at
FROM post p, posttag pt, tag t
WHERE p.post_id = pt.post_id AND pt.tag_id = t.tag_id AND t.tag_id = #{tagId} AND p.is_deleted = 0 AND p.is_public = 1
</select>
</mapper>