实现自定义查询

select tb.id from tb_blog tb 
left join tb_follow tf on tf.follow_user_id = tb.user_id 
where tf.user_id = 4033
order by tb.id desc;

application.yml

mybatis-plus:
  mapper-locations: classpath:/mapper/**/*.xml

mapper @Param对应mapper.xml sql的 #{userId}

package com.feed01.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.feed01.entity.Follow;
import com.feed01.entity.Voucher;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface FollowMapper extends BaseMapper<Follow> {
    List<Long> queryBlogs(@Param("userId") Long userId);
}

mapper.xml 路径在 resource/mapper/FollowMapper.xml

<?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.feed01.mapper.FollowMapper">
    <select id="queryBlogs" resultType="java.lang.Long" parameterType="java.lang.Long">
        select tb.id
        from tb_blog tb
        left join tb_follow tf on tf.follow_user_id = tb.user_id
        where tf.user_id = #{userId}
        order by tb.id desc;
    </select>
</mapper>

IService

package com.feed01.service;

import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

public interface IFollowService extends IService<Follow> {
    List<Long> queryBlogs(Long userId);
}

serviceImpl getBaseMapper().queryBlogs(userId) 是透过 interface FollowMapper

package com.feed01.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feed01.utils.UserHolder;

@Service
public class FollowServiceImpl extends ServiceImpl<FollowMapper, Follow> implements IFollowService {

    @Autowired
    private FollowMapper followMapper;

    @Override
    public List<Long> queryBlogs(Long userId) {
        return followMapper.queryBlogs(userId);
    }

    public void isFollow() {
        Long userId = UserHolder.getUser().getId();
        List<Long> blogIds = queryBlogs(userId);
    }
}