分页查询的实现
This commit is contained in:
@@ -15,7 +15,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.aos.fileidentify.mapper")
|
||||
public class AosFileIdentifyApplication {
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.aos.fileidentify.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@MapperScan("com.aos.fileidentify.mapper")
|
||||
public class MybatisPlusConfig {
|
||||
/**
|
||||
* IPage的分页使用的是拦截器,属于物理分页,好处就是处理大量数据时,查询速度快。
|
||||
* 有兴趣的同学可以看看什么是物理分页和逻辑分页。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
//向Mybatis过滤器链中添加分页拦截器
|
||||
interceptor.addInnerInterceptor(new
|
||||
PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.aos.fileidentify.common.ResultDTO;
|
||||
import com.aos.fileidentify.entity.Employee;
|
||||
import com.aos.fileidentify.service.EmployeeService;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -14,6 +15,8 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
@@ -45,4 +48,16 @@ public class EmployeeController {
|
||||
return this.employeeService.getAllEmployee();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all employee *
|
||||
*
|
||||
* @return the all employee
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@ApiOperation(value = "员工所有数据查询")
|
||||
@GetMapping(value = "/page")
|
||||
public ResultDTO<IPage<Employee>> getAllEmployee(@NotBlank Integer page, @NotBlank Integer pageSize) {
|
||||
return this.employeeService.getAllEmployee(page, pageSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.aos.fileidentify.service;
|
||||
|
||||
import com.aos.fileidentify.common.ResultDTO;
|
||||
import com.aos.fileidentify.entity.Employee;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,5 +23,8 @@ public interface EmployeeService {
|
||||
* @return the all employee
|
||||
* @since 0.0.1
|
||||
*/
|
||||
ResultDTO<IPage<Employee>> getAllEmployee(Integer page, Integer pageSize);
|
||||
|
||||
|
||||
ResultDTO<List<Employee>> getAllEmployee();
|
||||
}
|
||||
|
||||
@@ -4,12 +4,19 @@ import com.aos.fileidentify.common.ResultDTO;
|
||||
import com.aos.fileidentify.entity.Employee;
|
||||
import com.aos.fileidentify.mapper.EmployeeMapper;
|
||||
import com.aos.fileidentify.service.EmployeeService;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sun.net.httpserver.Authenticator;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -31,8 +38,15 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
private final EmployeeMapper employeeMapper;
|
||||
|
||||
@Override
|
||||
public ResultDTO<IPage<Employee>> getAllEmployee(Integer page, Integer pageSize) {
|
||||
|
||||
return new ResultDTO<>(true, 20000, this.employeeMapper.selectPage(new Page<>(page, pageSize), null), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDTO<List<Employee>> getAllEmployee() {
|
||||
return new ResultDTO<>(true, 20000, employeeMapper.selectList(new QueryWrapper<>()), null);
|
||||
QueryWrapper<Employee> queryWrapper = new QueryWrapper<>();
|
||||
return new ResultDTO<>(true, 20000, employeeMapper.selectList(queryWrapper.lambda().eq(Employee::getEmployeeKey, "1f1c8258ba2226e6a6851e62741418d7")), null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user