Browse Source

feat : 用例的分页查询,模糊查询

haihang
whh 4 months ago
parent
commit
ba42035174
  1. 11
      document/src/main/java/com/haihang/controller/CaseController.java
  2. 14
      document/src/main/java/com/haihang/entity/CasePageQueryDTO.java
  3. 21
      document/src/main/java/com/haihang/entity/PageResult.java
  4. 4
      document/src/main/java/com/haihang/mapper/CaseMapper.java
  5. 4
      document/src/main/java/com/haihang/service/CaseService.java
  6. 15
      document/src/main/java/com/haihang/service/impl/CaseServiceImpl.java
  7. 2
      document/src/main/java/com/haihang/utils/LoginInterceptor.java
  8. 16
      document/src/main/resources/application.yaml
  9. 17
      document/src/main/resources/mapper/CaseMapper.xml
  10. 17
      pom.xml

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

14
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;//每页有多大?
}

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

4
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<Case> pageQuery(CasePageQueryDTO casePageQueryDTO);
}

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

15
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<Case> page = caseMapper.pageQuery(casePageQueryDTO);
long total = page.getTotal();
List<Case> list = page.getResult();
return new PageResult((int) total,list);
}
}

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

16
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
mybatis:
#标注待解析的mapper的xml文件位置
mapper-locations: classpath:mapper/*.xml
#标注实体类位置
type-aliases-package: com.haihang.entity
configuration:
#开启驼峰命名
map-underscore-to-camel-case: true

17
document/src/main/resources/mapper/CaseMapper.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.haihang.mapper.CaseMapper">
<select id="pageQuery" resultType="com.haihang.entity.Case">
select * from case_table
<where>
<if test="caseName!= '' and caseName != null">
and case_name like concat('%',#{caseName},'%')
</if>
</where>
</select>
</mapper>

17
pom.xml

@ -21,6 +21,12 @@
</properties>
<dependencies>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
@ -40,6 +46,12 @@
<version>8.0.19</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@ -50,11 +62,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<!--hutool-->
<dependency>
<groupId>cn.hutool</groupId>

Loading…
Cancel
Save