mybatis-mapper / mapper

MyBatis Mapper
https://mapper.mybatis.io
Apache License 2.0
325 stars 47 forks source link

pagehelper 开启 supportMethodsArguments 对动态查询不起作用 #22

Closed li362692680 closed 1 year ago

li362692680 commented 2 years ago

pagehelper 开启 supportMethodsArguments 对动态查询不起作用,这个怎么解决??

abel533 commented 2 years ago

问题和当前mapper有关吗?

li362692680 commented 2 years ago

pagehelper 开启 supportMethodsArguments 拦截的是mapper方法的入参,userAutoMapper.selectByExample(example); 这种方式没法把分页参数传进去,要开启分页只能调用startPage方法或者增加page对象入参,这样的话supportMethodsArguments参数就失去意义了,咨询下有没有好的办法解决? UserAutoMapper userAutoMapper = sqlSession.getMapper(UserAutoMapper.class); Example example = userAutoMapper.example(); example.createCriteria().andLike(UserAuto::getAddress, "河北省%"); List userAutos = userAutoMapper.selectByExample(example);

abel533 commented 2 years ago

增加一个通用方法即可:

  /**
   * 根据 Example 条件分页查询
   *
   * @param example 条件
   * @return 实体列表
   */
  @Lang(Caching.class)
  @SelectProvider(type = ExampleProvider.class, method = "selectByExample")
  List<T> selectByExample(E example, RowBounds rowBounds);

  /**
   * 根据 Example 条件分页查询
   *
   * @param example 条件
   * @return 实体列表
   */
  @Lang(Caching.class)
  @SelectProvider(type = ExampleProvider.class, method = "selectByExample")
  List<T> selectByExample(E example, PageRowBounds rowBounds);

其中第二个方法使用了分页插件的 PageRowBounds,上面这两个方法不能同时存在,选择一个使用。