码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-01-10 12:41:22      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:技术   ceo   rom   ctr   group   shm   png   return   dha   

传参格式

技术图片

 

技术图片

 

 后端接收并在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>

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

标签:技术   ceo   rom   ctr   group   shm   png   return   dha   

原文地址:https://www.cnblogs.com/fenghh/p/12175324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!