(已解决)前后端联动多数组数据接收

前言:

真花了两天时间,基础太差了,也没什么算法基础,虽然也不需要什么算法...

顺道记录一下得了,小白太难了...


使用工具:

IDEA以及内置MYSQL语言数据库
Apifox(postman也行,就前端测试工具都行)


注意事项:

我使用的分层解耦:对这个没有了解的参考另一篇:

分层解耦复习


参考:

maven项目pom文件依赖参考:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>TianyiDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>TianyiDemo</name>
    <description>TianyiDemo</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.3</version>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
<!--            <scope>test</scope>-->
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
<!--            <scope>test</scope>-->

        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter-test</artifactId>
            <version>3.0.3</version>
<!--            <scope>test</scope>-->
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-web</artifactId>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>6.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>6.1.1</version>
        </dependency>
        <dependency>
            <groupId>io.leopard.boot</groupId>
            <artifactId>leopard-boot-requestmapping</artifactId>
            <version>0.9.20</version>
        </dependency>
        <dependency>
            <groupId>io.leopard.boot</groupId>
            <artifactId>leopard-boot-requestmapping</artifactId>
            <version>0.9.20</version>
        </dependency>
        <dependency>
            <groupId>io.leopard.boot</groupId>
            <artifactId>leopard-boot-requestmapping</artifactId>
            <version>0.9.20</version>
        </dependency>
        <dependency>
            <groupId>io.leopard.boot</groupId>
            <artifactId>leopard-boot-requestmapping</artifactId>
            <version>0.9.20</version>
        </dependency>
        <dependency>
            <groupId>io.leopard.boot</groupId>
            <artifactId>leopard-boot-requestmapping</artifactId>
            <version>0.9.20</version>
        </dependency>
        <dependency>
            <groupId>io.leopard.boot</groupId>
            <artifactId>leopard-boot-requestmapping</artifactId>
            <version>0.9.20</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

涉及数据库表及字段:

Circle表:

Section表:


实体类参考:
Cricle:

Section:

Result:(返回统一响应格式,更加便捷,可以不需要)


项目结构参考:


Controller层

Controller层:接受get请求,调用服务层getSAC方法,并且返回为Result统一响应格式



Service层

Service层:仅声明方法


实现层

Service层中的实现层:

使用MApper的getSectionAndCircle方法获取数据填充Section实体类,使用for循环,循环获取Section中的id,并且给到Mapper的getSectionID的方法中,且得到getBySectionID方法的数据并且赋值到circle实体类,最后由setter方法赋值回Section实体类中的List集合声明。


Mapper层

Mapper层:

第一个方法实现Section数据查询

第二个方法实现使用接受,服务层传来的SectionID进行查询


Apifox前端测试

成功解决传输


尾言

在查询的时候发现很多是使用MYbaits的xml映射文件进行数据映射填充,这个真不知道怎么弄,有会的大佬,麻烦评论一下...QAQ
好像映射了就不用mapper来注解sql语句了..具体还是不清楚

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值