Springboot集成mybatis plus时的分页使用

1.添加架包

com.baomidou.mybatis-plus

2.配置文件

# Tomcat
server:
  tomcat:
    uri-encoding: UTF-8
    max-threads: 1000
    min-spare-threads: 30
  port: 8080
  servlet:
    context-path: /

spring:
  profiles:
    active: dev
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
  servlet:
    multipart:
      max-file-size: 100MB
      max-request-size: 100MB
      enabled: true
  redis:
    database: 0
    host: 116.62.117.145
    port: 6379
    password: ziyun123      # 密码(默认为空)
    timeout: 6000ms  # 连接超时时长(毫秒)
    jedis:
      pool:
        max-active: 1000  # 连接池最大连接数(使用负值表示没有限制)
        max-wait: -1ms      # 连接池最大阻塞等待时间(使用负值表示没有限制)
        max-idle: 10      # 连接池中的最大空闲连接
        min-idle: 5       # 连接池中的最小空闲连接
  freemarker:
    suffix: .html
    request-context-attribute: request


renren:
  redis:
    open: true  # 是否开启redis缓存  true开启   false关闭
  shiro:
    redis: true # true表示shiro session存到redis里,需要开启redis,才会生效【分布式场景】
  schedule:
    open: true #打开 关闭定时任务


j2cache:
  configLocation: /j2cache-dev.properties
  openSpringCache: false

#mybatis
mybatis-plus:
  mapper-locations: classpath*:mapper/**/*.xml
  #实体扫描,多个package用逗号或者分号分隔
  typeAliasesPackage: io.renren.modules.*.entity;
  global-config:
    #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
    id-type: 0
    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
    field-strategy: 2
    #驼峰下划线转换
    db-column-underline: true
    #刷新mapper 调试神器
    refresh-mapper: true
    #数据库大写下划线转换
    #capital-mode: true
    # Sequence序列接口实现类配置
    #key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator
    #逻辑删除配置
    logic-delete-value: -1
    logic-not-delete-value: 0
    #自定义填充策略接口实现
    #meta-object-handler: com.baomidou.springboot.xxx
    #自定义SQL注入器
    sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
    call-setters-on-nulls: true

# 日志
logging:
#  level: debug
#  level.io.renren: debug
  path: logs/
  file: admin.log
  level:
      com.ziyun.erp.modules.*.dao: debug

单表分页

Java代码

 public static void testPageListUser() {
        Page page = new Page(1,10);

        Map params=new HashMap();
        condition.put("name", "测试");
        //String name="测试";
        List lstUser = userDao.selectUserList(page,params);
      
    }

在人人框架中使用

单表不用写sql

package com.ziyun.erp.modules.member.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.ziyun.erp.modules.member.dao.ConfigMemberLevelDao;
import com.ziyun.erp.modules.member.entity.ConfigMemberLevelEntity;
import com.ziyun.erp.modules.member.service.ConfigMemberLevelService;
import org.springframework.transaction.annotation.Transactional;


@Service("configMemberLevelService")
public class ConfigMemberLevelServiceImpl extends ServiceImpl implements ConfigMemberLevelService {

    @Autowired
    private ConfigMemberLevelDao configMemberLevelDao;

    @Override
    public PageUtils queryPage(Map params) {
        Page page = this.selectPage(
                new Query(params).getPage(),
                new EntityWrapper()
        );

        return new PageUtils(page);
    }

多表查询分页需自己写sql

ServiceImpl

package com.ziyun.erp.modules.member.service.impl;

import com.ziyun.erp.common.utils.MD5;
import com.ziyun.erp.modules.member.dao.*;
import com.ziyun.erp.modules.member.entity.*;
import io.renren.common.exception.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.ziyun.erp.modules.member.service.UserBaseInfoService;
import org.springframework.transaction.annotation.Transactional;


@Service("userBaseInfoService")
public class UserBaseInfoServiceImpl extends ServiceImpl implements UserBaseInfoService {

    @Autowired
    private UserBaseInfoDao userBaseInfoDao;
    @Autowired
    private UserWalletDao userWalletDao;
    @Autowired
    private UserAdvanceDao userAdvanceDao;
    @Autowired
    private UserCreditDao userCreditDao;
    @Autowired
    private UserPointDao userPointDao;
    @Autowired
    private UserMemberLevelDao userMemberLevelDao;
    @Autowired
    private UserLoginAccountDao userLoginAccountDao;
    @Override
    public PageUtils selectAllList(Map params) {
        Page page = new Page<>();
        page.setCurrent(Integer.valueOf(params.get("page").toString()));
        page.setSize(Integer.valueOf(params.get("limit").toString()));
        List list = userBaseInfoDao.getAllUserInfo(page,params);
        page.setRecords(list);
        return new PageUtils(page);
    }

Dao层方法的参数传入Pagination page即可

List getAllUserInfo(Pagination page,Map map);

Xml

 

 

你可能感兴趣的:(Springboot集成mybatis plus时的分页使用)