美文网首页
mybatis升级mybatis-plus

mybatis升级mybatis-plus

作者: 指下光年 | 来源:发表于2021-12-16 23:02 被阅读0次
  1. 添加mybatis-plus依赖
<dependency>
   <groupId>com.baomidou</groupId>
   <artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
  1. 修改配置文件
mybatis-plus:
  type-aliases-package: com.ruoyi.**.domain
  mapper-locations: classpath*:mapper/**/*Mapper.xml
  config-location: classpath:mybatis/mybatis-config.xml
  1. 修改mybatisConfig类
package com.ruoyi.framework.config;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author weiwei
 * @since 2021/12/16 22:40
 */
@Configuration
@MapperScan("com.ruoyi.**.mapper")
public class MybatisPlusConfig {
    /**
     * 分页插件
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
        // paginationInterceptor.setOverflow(false);
        // 设置最大单页限制数量,默认 500 条,-1 不受限制
        // paginationInterceptor.setLimit(500);
        return paginationInterceptor;
    }

    /**
     * 乐观锁插件
     * @return
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }

}

4.mapper service 继承mybatis-plus

  • mapper
public interface SysConfigMapper extends BaseMapper<SysConfig>{
}
  • service
@Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService{
}
  1. 测试


    image.png

相关文章

网友评论

      本文标题:mybatis升级mybatis-plus

      本文链接:https://www.haomeiwen.com/subject/lqsbfrtx.html