mybatis-plus返回查詢總記錄數方式

mybatis-plus返回查詢總記錄數

mp框架提供瞭selectCount方法,來查詢總記錄數;

需求:

查找薪水大於3500 名字裡有“小”的 員工的個數

sql實現:

select count(*) from t_employee where salary>3500 and name like ‘%小%'

代碼實現:

@Test
public void selectCountByQueryWrapper11(){
    QueryWrapper<Employee> queryWrapper=new QueryWrapper();
    // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query();
    queryWrapper.gt("salary",3500).like("name","小");
    Integer count = employeeMapper.selectCount(queryWrapper);
    System.out.println(count);
}

mybatis-plus分頁查詢,總條數為零的解決

package com.integration.config;
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;
@Configuration
@MapperScan("com.integration.mapper")
public class MybatisPlusConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor page = new PaginationInterceptor();
        return page;
    }
}

以上為個人經驗,希望能給大傢一個參考,也希望大傢多多支持WalkonNet。

推薦閱讀: