diff --git a/src/main/java/com/aos/fileidentify/AosFileIdentifyApplication.java b/src/main/java/com/aos/fileidentify/AosFileIdentifyApplication.java index 923012a..1275a70 100644 --- a/src/main/java/com/aos/fileidentify/AosFileIdentifyApplication.java +++ b/src/main/java/com/aos/fileidentify/AosFileIdentifyApplication.java @@ -15,7 +15,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; * @since 0.0.1 */ @SpringBootApplication -@MapperScan("com.aos.fileidentify.mapper") public class AosFileIdentifyApplication { /** diff --git a/src/main/java/com/aos/fileidentify/config/MybatisPlusConfig.java b/src/main/java/com/aos/fileidentify/config/MybatisPlusConfig.java new file mode 100644 index 0000000..408a3ae --- /dev/null +++ b/src/main/java/com/aos/fileidentify/config/MybatisPlusConfig.java @@ -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; + } + +} diff --git a/src/main/java/com/aos/fileidentify/controller/EmployeeController.java b/src/main/java/com/aos/fileidentify/controller/EmployeeController.java index 7c3ac44..20946f3 100644 --- a/src/main/java/com/aos/fileidentify/controller/EmployeeController.java +++ b/src/main/java/com/aos/fileidentify/controller/EmployeeController.java @@ -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; + /** *

Company: 成都返空汇网络技术有限公司

*

Description:

@@ -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> getAllEmployee(@NotBlank Integer page, @NotBlank Integer pageSize) { + return this.employeeService.getAllEmployee(page, pageSize); + } + } diff --git a/src/main/java/com/aos/fileidentify/service/EmployeeService.java b/src/main/java/com/aos/fileidentify/service/EmployeeService.java index 5bed169..7aaf1e8 100644 --- a/src/main/java/com/aos/fileidentify/service/EmployeeService.java +++ b/src/main/java/com/aos/fileidentify/service/EmployeeService.java @@ -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> getAllEmployee(Integer page, Integer pageSize); + + ResultDTO> getAllEmployee(); } diff --git a/src/main/java/com/aos/fileidentify/service/impl/EmployeeServiceImpl.java b/src/main/java/com/aos/fileidentify/service/impl/EmployeeServiceImpl.java index 2358294..59764f4 100644 --- a/src/main/java/com/aos/fileidentify/service/impl/EmployeeServiceImpl.java +++ b/src/main/java/com/aos/fileidentify/service/impl/EmployeeServiceImpl.java @@ -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> getAllEmployee(Integer page, Integer pageSize) { + + return new ResultDTO<>(true, 20000, this.employeeMapper.selectPage(new Page<>(page, pageSize), null), null); + } + @Override public ResultDTO> getAllEmployee() { - return new ResultDTO<>(true, 20000, employeeMapper.selectList(new QueryWrapper<>()), null); + QueryWrapper queryWrapper = new QueryWrapper<>(); + return new ResultDTO<>(true, 20000, employeeMapper.selectList(queryWrapper.lambda().eq(Employee::getEmployeeKey, "1f1c8258ba2226e6a6851e62741418d7")), null); } }