blob: 0cba5c1051c31f11eb3fd17fec210e8d903cc1ca [file] [log] [blame]
wuchimedese5722e32025-04-13 17:38:50 +08001package com.example.g8backend.mapper;
2
3import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4import com.example.g8backend.entity.Post;
5import org.apache.ibatis.annotations.Mapper;
6import org.apache.ibatis.annotations.Param;
夜雨声烦4527a722025-04-23 17:04:25 +08007import org.apache.ibatis.annotations.Select;
wuchimedese5722e32025-04-13 17:38:50 +08008
9import java.util.List;
10
11@Mapper
12public interface PostMapper extends BaseMapper<Post> {
13 List<Post> getPostsByUserId(@Param("userId") Long userId);
夜雨声烦4527a722025-04-23 17:04:25 +080014
15 @Select("<script>" +
16 "SELECT p.* " +
17 "FROM posts p " +
18 "LEFT JOIN post_tag pt ON p.post_id = pt.post_id " +
19 "LEFT JOIN tags t ON pt.tag_id = t.tag_id " +
20 "LEFT JOIN users u ON p.user_id = u.user_id " +
21 "WHERE (p.post_title LIKE CONCAT('%', #{keyword}, '%') OR p.post_content LIKE CONCAT('%', #{keyword}, '%')) " +
22 "<if test='tagIds != null and tagIds.size() > 0'> " +
23 "AND pt.tag_id IN " +
24 "<foreach item='tagId' collection='tagIds' open='(' separator=',' close=')'> " +
25 "#{tagId} " +
26 "</foreach> " +
27 "</if>" +
28 "<if test='author != null'> " +
29 "AND u.user_name = #{author} " +
30 "</if>" +
31 "</script>")
32 List<Post> searchPosts(@Param("keyword") String keyword,
33 @Param("tagIds") List<Long> tagIds, // 改成接受一个tagIds列表
34 @Param("author") String author);
wuchimedese5722e32025-04-13 17:38:50 +080035}