From ba4203517489d1df09946038a3065058389e0e40 Mon Sep 17 00:00:00 2001 From: whh <2846845743@qq.com> Date: Fri, 27 Sep 2024 16:43:21 +0800 Subject: [PATCH] =?UTF-8?q?feat=20:=20=E7=94=A8=E4=BE=8B=E7=9A=84=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2=EF=BC=8C=E6=A8=A1=E7=B3=8A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haihang/controller/CaseController.java | 11 ++++++++++ .../com/haihang/entity/CasePageQueryDTO.java | 14 +++++++++++++ .../java/com/haihang/entity/PageResult.java | 21 +++++++++++++++++++ .../java/com/haihang/mapper/CaseMapper.java | 4 ++++ .../java/com/haihang/service/CaseService.java | 4 ++++ .../haihang/service/impl/CaseServiceImpl.java | 15 +++++++++++++ .../com/haihang/utils/LoginInterceptor.java | 2 +- document/src/main/resources/application.yaml | 18 +++++++++++++--- .../src/main/resources/mapper/CaseMapper.xml | 17 +++++++++++++++ pom.xml | 17 ++++++++++----- 10 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 document/src/main/java/com/haihang/entity/CasePageQueryDTO.java create mode 100644 document/src/main/java/com/haihang/entity/PageResult.java create mode 100644 document/src/main/resources/mapper/CaseMapper.xml diff --git a/document/src/main/java/com/haihang/controller/CaseController.java b/document/src/main/java/com/haihang/controller/CaseController.java index d29d4fb..1544398 100644 --- a/document/src/main/java/com/haihang/controller/CaseController.java +++ b/document/src/main/java/com/haihang/controller/CaseController.java @@ -2,11 +2,15 @@ package com.haihang.controller; import com.haihang.entity.Case; +import com.haihang.entity.CasePageQueryDTO; +import com.haihang.entity.PageResult; import com.haihang.service.CaseService; import com.haihang.utils.Result; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +@Slf4j @RestController @RequestMapping("/case") public class CaseController { @@ -41,4 +45,11 @@ public class CaseController { } + @GetMapping("/page") + public Result page(CasePageQueryDTO casePageQueryDTO){ + log.info("用例分页查询:{}",casePageQueryDTO); + PageResult pageResult = caseService.pageQuery(casePageQueryDTO); + return Result.ok(pageResult); + } + } diff --git a/document/src/main/java/com/haihang/entity/CasePageQueryDTO.java b/document/src/main/java/com/haihang/entity/CasePageQueryDTO.java new file mode 100644 index 0000000..db171a5 --- /dev/null +++ b/document/src/main/java/com/haihang/entity/CasePageQueryDTO.java @@ -0,0 +1,14 @@ +package com.haihang.entity; + + +import lombok.Data; + +import java.io.Serializable; + +//用例分页查询DTO +@Data +public class CasePageQueryDTO implements Serializable { + private String caseName; + private int page;//当前页码 + private int pageSize;//每页有多大? +} diff --git a/document/src/main/java/com/haihang/entity/PageResult.java b/document/src/main/java/com/haihang/entity/PageResult.java new file mode 100644 index 0000000..d8df0c0 --- /dev/null +++ b/document/src/main/java/com/haihang/entity/PageResult.java @@ -0,0 +1,21 @@ +package com.haihang.entity; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +//分页结果 +@Data +@NoArgsConstructor +public class PageResult { + private int total; + private List records; + + public PageResult(int total, List records) { + this.total = total; + this.records = records; + } +} diff --git a/document/src/main/java/com/haihang/mapper/CaseMapper.java b/document/src/main/java/com/haihang/mapper/CaseMapper.java index 3ce1f0e..bea2b50 100644 --- a/document/src/main/java/com/haihang/mapper/CaseMapper.java +++ b/document/src/main/java/com/haihang/mapper/CaseMapper.java @@ -1,6 +1,8 @@ package com.haihang.mapper; +import com.github.pagehelper.Page; import com.haihang.entity.Case; +import com.haihang.entity.CasePageQueryDTO; import org.apache.ibatis.annotations.*; import java.util.List; @@ -30,4 +32,6 @@ public interface CaseMapper { @Update("update case_table set is_leaf = #{i} where id =#{parentId}") void updateIsLeaf(int i, int parentId); + + Page pageQuery(CasePageQueryDTO casePageQueryDTO); } diff --git a/document/src/main/java/com/haihang/service/CaseService.java b/document/src/main/java/com/haihang/service/CaseService.java index 326c70d..f4025c4 100644 --- a/document/src/main/java/com/haihang/service/CaseService.java +++ b/document/src/main/java/com/haihang/service/CaseService.java @@ -1,6 +1,8 @@ package com.haihang.service; import com.haihang.entity.Case; +import com.haihang.entity.CasePageQueryDTO; +import com.haihang.entity.PageResult; import com.haihang.utils.Result; public interface CaseService { @@ -13,4 +15,6 @@ public interface CaseService { Result update(Case aCase); Result getById(int id); + + PageResult pageQuery(CasePageQueryDTO casePageQueryDTO); } diff --git a/document/src/main/java/com/haihang/service/impl/CaseServiceImpl.java b/document/src/main/java/com/haihang/service/impl/CaseServiceImpl.java index 853c87c..cc85b4d 100644 --- a/document/src/main/java/com/haihang/service/impl/CaseServiceImpl.java +++ b/document/src/main/java/com/haihang/service/impl/CaseServiceImpl.java @@ -1,6 +1,10 @@ package com.haihang.service.impl; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import com.haihang.entity.Case; +import com.haihang.entity.CasePageQueryDTO; +import com.haihang.entity.PageResult; import com.haihang.mapper.CaseMapper; import com.haihang.service.CaseService; import com.haihang.utils.Result; @@ -94,5 +98,16 @@ public class CaseServiceImpl implements CaseService { return Result.ok(aCase); } + @Override + public PageResult pageQuery(CasePageQueryDTO casePageQueryDTO) { + //开始分页查询 + PageHelper.startPage(casePageQueryDTO.getPage(),casePageQueryDTO.getPageSize()); + Page page = caseMapper.pageQuery(casePageQueryDTO); + long total = page.getTotal(); + List list = page.getResult(); + + return new PageResult((int) total,list); + } + } diff --git a/document/src/main/java/com/haihang/utils/LoginInterceptor.java b/document/src/main/java/com/haihang/utils/LoginInterceptor.java index a2c6024..c229375 100644 --- a/document/src/main/java/com/haihang/utils/LoginInterceptor.java +++ b/document/src/main/java/com/haihang/utils/LoginInterceptor.java @@ -4,9 +4,9 @@ package com.haihang.utils; import cn.hutool.core.bean.BeanUtil; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.haihang.entity.UserInfo; import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerInterceptor; import javax.annotation.Resource; diff --git a/document/src/main/resources/application.yaml b/document/src/main/resources/application.yaml index 912bad6..5bb5e02 100644 --- a/document/src/main/resources/application.yaml +++ b/document/src/main/resources/application.yaml @@ -1,6 +1,10 @@ server: port: 8081 spring: + + main: + allow-circular-references: true + application: name: hmdp datasource: @@ -20,8 +24,16 @@ spring: time-between-eviction-runs: 10s jackson: default-property-inclusion: non_null # JSON处理时忽略非空字段 -mybatis-plus: - type-aliases-package: com.hmdp.entity # 别名扫描包 logging: level: - com.haihang: debug \ No newline at end of file + com.haihang: debug +mybatis: + + #标注待解析的mapper的xml文件位置 + mapper-locations: classpath:mapper/*.xml + #标注实体类位置 + type-aliases-package: com.haihang.entity + configuration: + #开启驼峰命名 + map-underscore-to-camel-case: true + diff --git a/document/src/main/resources/mapper/CaseMapper.xml b/document/src/main/resources/mapper/CaseMapper.xml new file mode 100644 index 0000000..a284fb6 --- /dev/null +++ b/document/src/main/resources/mapper/CaseMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/pom.xml b/pom.xml index 81b443d..3c538d2 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,12 @@ + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.2.12 + + org.springframework.boot spring-boot-starter-data-redis @@ -40,6 +46,12 @@ 8.0.19 + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.0 + + org.projectlombok lombok @@ -50,11 +62,6 @@ spring-boot-starter-test test - - com.baomidou - mybatis-plus-boot-starter - 3.5.2 - cn.hutool