mybatis-plus 3.4 分页无效问题

配置MybatisPlusConfig

@Configuration
@EnableTransactionManagement
@MapperScan(basePackages = {"com.longtu.**.mapper"})
public class MybatisPlusConfig {


    /**
     * 分页插件,自动识别数据库类型 多租户,请参考官网【插件扩展】
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }


    /**
     * 自动填充数据库创建人、创建时间、更新人、更新时间
     */
    /*@Bean
    public GlobalConfig globalConfig() {
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setMetaObjectHandler(new MetaHandler());
        return globalConfig;
    }*/

    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> configuration.setUseDeprecatedExecutor(false);
    }

引入mybatis-plus依赖

 

            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.4.0</version>
            </dependency>
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-generator</artifactId>
                <version>3.4.0</version>
            </dependency>

依然无效  说明配置类没有被正确加载 ,终极绝招 在springboot启动类上强制加载 MybatisPlusConfig配置类

 

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableSwagger2
@MapperScan("com.longtu.wms.mapper")
@Import(MybatisPlusConfig.class)
public class WmsApplication {
    public static void main(String[] args) {
        SpringApplication.run(WmsApplication.class);
    }

至此问题解决

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
MyBatis-Plus是一个基于MyBatis的增强工具,提供了许多便捷的功能来简化开发。其中,MyBatis-Plus-join是MyBatis-Plus的一个扩展模块,用于支持关联查询。 在使用MyBatis-join的依赖。可以在项目的pom.xml文件中添加如下依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-extension</artifactId> <version>3.4.3.1</version> </dependency> ``` 2. 在实体类中定义关联关系。使用MyBatis-Plus-join时,需要在实体类中定义关联关系,可以使用`@TableField`注解来指定关联字段。例如: ```java public class User { private Long id; private String name; @TableField(exist = false) private List<Role> roles; // getter and setter } public class Role { private Long id; private String roleName; // getter and setter } ``` 3. 编写Mapper接口。在Mapper接口中,可以使用`@Select`注解来编写关联查询的SQL语句。例如: ```java @Mapper public interface UserMapper extends BaseMapper<User> { @Select("SELECT u.*, r.* FROM user u LEFT JOIN user_role ur ON u.id = ur.user_id LEFT JOIN role r ON ur.role_id = r.id") @Results({ @Result(property = "id", column = "id"), @Result(property = "name", column = "name"), @Result(property = "roles", column = "id", many = @Many(select = "com.example.mapper.RoleMapper.selectByUserId")) }) List<User> selectUserWithRoles(Page<User> page); } ``` 4. 编写关联查询的子查询。在上面的例子中,使用了`@Many`注解来指定关联查询的子查询方法。例如: ```java @Mapper public interface RoleMapper extends BaseMapper<Role> { @Select("SELECT r.* FROM role r LEFT JOIN user_role ur ON r.id = ur.role_id WHERE ur.user_id = #{userId}") List<Role> selectByUserId(Long userId); } ``` 5. 调用分页查询方法。在Service层或者Controller层中,可以调用Mapper接口中定义的分页查询方法来进行查询。例如: ```java @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public IPage<User> getUserWithRoles(Page<User> page) { return userMapper.selectUserWithRoles(page); } } ``` 以上就是使用MyBatis-Plus-join进行分页查询的基本步骤。通过定义关联关系和编写关联查询的SQL语句,可以方便地进行关联查询并实现分页功能。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值