mybatis-plus自定义sql,使用@select自定义或使用xml文件自定义mp的sql

注意:不需要手动添加where

参数是构造器,使用@select

@Mapper
@Component
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user ${ew.customSqlSegment}")
    Page MyPage1(Page<User> page, @Param("ew") Wrapper<User> queryWrapper);
}

 

 

使用xml

效果和注解是相同的

 <select id="myPage" resultType="com.fj.entity.User">
     select * from user ${ew.customSqlSegment}
 </select>

使用

@Mapper
@Component
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user ${ew.customSqlSegment}")
    Page MyPage(Page<User> page, @Param("ew") Wrapper<User> queryWrapper);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
MyBatis-Plus提供了一个方便的分页插件来进行分页查询。你可以通过在mapper.xml文件中配置相关的SQL语句来结合使用。 首先,你需要在mapper.xml文件中引入MyBatis-Plus的分页标签。在mapper标签的顶部添加以下命名空间声明: ```xml xmlns:mp="http://mybatis.org/schema/mybatis-plus" ``` 然后,在需要分页查询的SQL语句中,使用MyBatis-Plus的分页标签来配置分页参数。例如,使用`<mp:page>`标签指定分页参数: ```xml <select id="selectUsers" resultMap="UserResultMap"> SELECT * FROM users <where> <!-- 查询条件 --> </where> <mp:page current="${pageNum}" size="${pageSize}" total="${total}" reasonable="${reasonable}"/> </select> ``` 在上面的示例中,`${pageNum}`表示当前页码,`${pageSize}`表示每页显示的记录数,`${total}`表示总记录数,`${reasonable}`表示是否启用合理化分页。 最后,你可以在Java代码中使用MyBatis-Plus提供的`Page`对象来进行分页查询。例如: ```java import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; public interface UserMapper extends BaseMapper<User> { IPage<User> selectUsers(Page<User> page, @Param("condition") UserCondition condition); } ``` 在上面的示例中,`Page<User>`表示分页参数类型,`UserCondition`表示查询条件类型。 通过以上配置和代码,你就可以使用MyBatis-Plus的分页插件来实现分页查询了。记得在使用分页插件之前,需要在配置文件中开启分页插件的支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值