Mybatis-plus笔记

1.特性:

    1.无侵入:引入mybatis-plus不会对mybatis框架产生任何影响因为他是在mybatis的基础上进行了扩展

    2.依赖少:仅仅依赖mybatis和mybatis-Spring

    3.损耗小:启动会自动注入基本的curd(增删改查)操作性能基本无损耗直接面向对象操作

    4.预防sql注入:内置sql注入剥离器,防止sql注入

    5.多主键策略:支持4中的主键策略,内含分布式唯一id生成器

    6.支持热加载:mapper对应的xml支持热加载

    热加载:在运行时重新加载class(开发环境)基于字节码的更改,适用于开发

    热部署:在运行时从新加载整个应用(生产环境),清空内存从新打包 ,适用于项目

2.使用Wrapper条件类实现分页

    server层:

        Wrapper<Ship> wrapper = new EntityWrapper<>();//条件类

        wrapper.where("user_id={0}",uid);//增加条件

        Page<Ship> shipPage = new Page<>(pageNum, pageSize);//分页类

        List<Ship> ships = shipMapper.selectPages(shipPage, wrapper);//去dao

        return new PageResult<>(shipPage.getTotal(), ships);

    daoMapper层: 

        List<Ship> selectPages(Page<Ship> page, @Param("ew") Wrapper<Ship> wrapper);

    mapper.xml层:

        <select id="selectPages" resultMap="BaseResultMap">

          select s.*,f.fsa_flag from tb_ship s left join tb_flag_state_authority f on s.fsa_id=f."id"

          <where>

            ${ew.sqlSegment}

          </where>
        </select>

猜你喜欢

转载自www.cnblogs.com/HQ0422/p/10863008.html