blob: 0cba5c1051c31f11eb3fd17fec210e8d903cc1ca [file] [log] [blame]
package com.example.g8backend.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.g8backend.entity.Post;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface PostMapper extends BaseMapper<Post> {
List<Post> getPostsByUserId(@Param("userId") Long userId);
@Select("<script>" +
"SELECT p.* " +
"FROM posts p " +
"LEFT JOIN post_tag pt ON p.post_id = pt.post_id " +
"LEFT JOIN tags t ON pt.tag_id = t.tag_id " +
"LEFT JOIN users u ON p.user_id = u.user_id " +
"WHERE (p.post_title LIKE CONCAT('%', #{keyword}, '%') OR p.post_content LIKE CONCAT('%', #{keyword}, '%')) " +
"<if test='tagIds != null and tagIds.size() > 0'> " +
"AND pt.tag_id IN " +
"<foreach item='tagId' collection='tagIds' open='(' separator=',' close=')'> " +
"#{tagId} " +
"</foreach> " +
"</if>" +
"<if test='author != null'> " +
"AND u.user_name = #{author} " +
"</if>" +
"</script>")
List<Post> searchPosts(@Param("keyword") String keyword,
@Param("tagIds") List<Long> tagIds, // 改成接受一个tagIds列表
@Param("author") String author);
}