前端传多个数组集合,后端接收并匹配

Posted hao踏雪无痕

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了前端传多个数组集合,后端接收并匹配相关的知识,希望对你有一定的参考价值。

传参格式

 

 

 后端接收并在SQL匹配

 @GetMapping(value = "xj/node/openApi/subnets")
    @ApiOperation(value = "查询openApi子网接口", httpMethod = "GET", response = String.class)
    public Map<String, Object> listResourceOpenApiSubnets(
            @ApiParam(value = "子网地址", required = false) @RequestParam(required = false, name = "subnetIp") String subnetIp,
            @ApiParam(value = "子网名称", required = false) @RequestParam(required = false, name = "subnetName") String subnetName,
            @ApiParam(value = "关键字", required = false) @RequestParam(required = false, name = "key") String key,
            @ApiParam(value = "子网", required = false) @RequestParam(required = false, name = "subnetIps") String subnetIps) {
        HashMap<String, Object> paramMap = new HashMap<>();
        Optional.ofNullable(subnetIp).map(t -> paramMap.put("subnetIp", t));
        Optional.ofNullable(subnetName).map(t -> paramMap.put("subnetName", t));
        Optional.ofNullable(key).map(t -> paramMap.put("key", t));
        String[] subnetIpArray = subnetIps.split(",");
        List<String> subnetIpList = new ArrayList<>();
        for (String item : subnetIpArray) {
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append("\'");
            stringBuffer.append(item);
            stringBuffer.append("\'");
            subnetIpList.add(stringBuffer.toString());
        }
        paramMap.put("subnetIpList", StringUtils.join(subnetIpList, ","));

        val resultList = resourceService.listResourceOpenApiSubnets(getCurrentLoginId(), paramMap);
        val resultMap = new HashMap<String, Object>();
        resultMap.put("record", resultList);
        return resultMap;
    }

SQL

<select id="selectRNOpenApiSubnets" parameterType="map" resultType="java.util.LinkedHashMap">
        <![CDATA[
            SELECT a.*,b.use FROM xjyd_openapi_subnet a
            left join (SELECT a.subnet_id,group_CONCAT(a.`use`) `use` FROM xjyd_openapi_subnet_use a GROUP BY a.subnet_id) b on a.subnet_id = b.subnet_id
        ]]>
        <where>
            <if test=\'subnetName != null\'>
                <![CDATA[ and a.subnet_name = #{subnetName} ]]>
            </if>
            <if test=\'subnetIp != null\'>
                <![CDATA[ and CONCAT(\'%.\',a.subnet_ip,\'.%\') like CONCAT(\'%.\',#{subnetIp},\'.%\') ]]>
            </if>
            <if test=\'subnetIpList != null\'>
                <![CDATA[ and a.subnet_ip in (${subnetIpList}) ]]>
            </if>
            <if test=\'key != null\'>
                <![CDATA[ and (CONCAT(\'%.\',a.subnet_ip,\'.%\') like CONCAT(\'%.\',#{key},\'.%\')
                               or a.subnet_name like CONCAT(\'%\',#{key},\'%\')
                               )
                ]]>
            </if>
        </where>
    </select>

以上是关于前端传多个数组集合,后端接收并匹配的主要内容,如果未能解决你的问题,请参考以下文章

前端需要java后端传多个对象数据怎么传?

前端传字符串后端能解析成数字嘛

前端批量上传图片后端怎么接收?

axios将数据从前端传到后端是对象还是数组

FormData如何向后端传递数组

后端接收不到前端传入的header参数信息