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

传参格式

 

 

 后端接收并在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>
posted @ 2020-01-10 11:33  hao踏雪无痕  阅读(5194)  评论(0编辑  收藏  举报