mybatis-plus 多表关联分页

mybatis-plus 多表关联分页

今天在写个人博客时遇到了这个问题 ,在这里记录一下,方便忘记时查找

controller层

 	@Autowired
    ArticleService articleService;
    @Test
    void moreTablePage(){
    	//参数1 第几页 
    	//参数2 每页显示多少
    	//参数3 分页模糊查询的条件 
        Page<Article> page=articleService.selectListPage(1, 5,"");
       page.getRecords().forEach(System.out::println);

    }

service层

public interface ArticleService extends IService<Article> {
		//参数1 第几页 
    	//参数2 每页显示多少
    	//参数3 分页模糊查询的条件 
    Page<Article> selectListPage(int current, int number,String like);
}

serviceImpl层

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    @Override
    public Page<Article> selectListPage(int current, int number,String like) {
        // 新建分页
        Page<Article> page = new Page<Article>(current, number);

        // 返回分页结果 like 为模糊查询条件
        return page.setRecords(this.baseMapper.dyGetUserList(page,like));
    }
}

dao层(mapper层)

@Repository
@Mapper
public interface ArticleMapper extends BaseMapper<Article> {
    List<Article> dyGetUserList(Page<Article> page, @Param("like") String like);
}

mapper.xml

这里我们写一个关联模糊条件查询

<select id="dyGetUserList" resultType="com.zhao.pojo.Article">
        select a.*,s.hits,s.comments_num,s.zan from article a
        left join statistic s on a.article_id=s.article_id
        where 1=1
        <if test="like != null and like !=''">
            and a.title like concat('%',#{like},'%')
        </if>
        order by a.create_time desc
    </select>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值