当前位置:主页 > 软件编程 > JAVA代码 >

mybatis-plus返回查询总记录数方式

时间:2022-10-20 10:15:21 | 栏目:JAVA代码 | 点击:

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;
    }
}

您可能感兴趣的文章:

相关文章