您当前的位置: 首页 >  mybatis

梁云亮

暂无认证

  • 0浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

MyBatisPlus XML 自定义分页

梁云亮 发布时间:2021-12-05 19:54:21 ,浏览量:0

Mapper接口
@Mapper
public interface GoodsMapper extends BaseMapper {
    /**
     * 根据条件分页查询
     *
     * @param page
     * @param goodsCondition
     * @return
     */
    IPage selectPage(IPage page, @Param("condition") GoodsCondition goodsCondition);
}

注意:方法的返回值为IPage对象,只有这样,在使用时,查询出来的结果才会自动赋值给IPage对象。参看下面的测试方法。

映射文件

DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

    
        
        id, `name`, barcode, price1, price2, amount, img, pics, category_id, country_id,
        addr, sell_point, priority, `status`, create_time, update_time
    
    
    
        select
        
        from tb_goods
        
            
                and id = #{condition.id,jdbcType=BIGINT}
            
            
                and name = #{condition.name,jdbcType=VARCHAR}
            
            
                and barcode = #{condition.barcode,jdbcType=VARCHAR}
            
            
                and price1 = #{condition.price1,jdbcType=DECIMAL}
            
            
                and price2 = #{condition.price2,jdbcType=DECIMAL}
            
            
                and amount = #{condition.amount,jdbcType=INTEGER}
            
            
                and category_id = #{condition.categoryId,jdbcType=INTEGER}
            
            
                and country_id = #{condition.countryId,jdbcType=INTEGER}
            
            
                and addr = #{condition.addr,jdbcType=VARCHAR}
            
            
                and sell_point = #{condition.sellPoint,jdbcType=VARCHAR}
            
            
                and status = #{condition.status,jdbcType=INTEGER}
            
            
                and create_time between #{condition.start,jdbcType=TIMESTAMP} and #{condition.end,jdbcType=TIMESTAMP}
            
        
    

测试代码
@SpringBootTest
class GoodsMapperTest {

    @Resource
    private GoodsMapper goodsMapper;

    @Test
    void selectPage() {
        IPage page = new Page(1, 10);
        GoodsCondition goodsCondition = GoodsCondition.builder()
//                .id(3L)
//                .name("fdsa")
//                .price1(BigDecimal.valueOf(324))
//                .start(LocalDateTime.now())
//                .end(LocalDateTime.now())
                .build();
        goodsMapper.selectPage(page, goodsCondition);

        System.out.println(page);
    }
}
关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0418s