【Mybatis】传入多个参数查询

原创
10/18 16:12
阅读数 11

描述:

传递多个参数进行查询,查询出集合数据

数据库传入参数数据:

["b7cd68117f724a4489de9eb2ed071801","5","6","7"]

java数据转换:

String goodsCodes = object.getString("codes");
if(!"[]".equals(goodsCodes)){
    String[] arr = goodsCodes.replace("[", "").replace("]", "").split(",");
    jsonObject.put("goodsIds", Arrays.asList(arr));

    // 查询商品详细
    goodsInfoList = isubjectPageDao.getGoodsInfoByGoodsId(jsonObject);

SQL:

<select id="getGoodsInfoByGoodsId" resultType="com.alibaba.fastjson.JSONObject" parameterType="Map">
    SELECT
        title,
        master_img,
        sale_price,
        item_sku_code
    FROM
        sku
    WHERE
        item_sku_code IN
    <foreach collection="goodsIds"  close=")" open="("  separator=","  index="" item="item">
        ${item}
    </foreach>
    AND
    website_code = #{websiteCode}
</select>

结果:

{
    "msg": "成功",
    "errorCode": 200,
    "timestamp": 1602829613,
    "data": {
        "pageNum": 0,
        "rows": 4,
        "total": 4,
        "pages": 0,
        "list": [
            {
                "salePrice": 301.00,
                "itemSkuCode": "5",
                "masterImg": "https://cdn.huaduocai.net/Storage/Shop/3/user/admin/1830545471246700.jpg",
                "title": "百合葵1"
            },
            {
                "salePrice": 302.00,
                "itemSkuCode": "6",
                "masterImg": "https://cdn.huaduocai.net/Storage/Shop/3/user/admin/1830530804712400.jpg",
                "title": "向日葵121"
            },
            {
                "salePrice": 304.00,
                "itemSkuCode": "8",
                "masterImg": "https://cdn.huaduocai.net/Storage/Shop/3/user/admin/1830558026180100.jpg",
                "title": "向日葵test"
            },
            {
                "salePrice": 230.00,
                "itemSkuCode": "b7cd68117f724a4489de9eb2ed071801",
                "masterImg": "https://cdn.huaduocai.net/Storage/Shop/3/user/admin/28315932130730.jpg",
                "title": "23"
            }
        ]
    }
}

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部