顺义城区网站建设,国外wordpress主题优化,国际新闻界期刊,徐州木塑模板很多时候mysql的一列当中存的是json格式的数据#xff0c;这时候如果要查询某个key对应的值的时候要如何查询呢#xff0c;这里记录一种查询方法#xff1a;
json列的值#xff1a; {“InventoryMainTypeCode”: 1, “InventoryMainTypeName”: “GOOD”}
现在要查询Inve…很多时候mysql的一列当中存的是json格式的数据这时候如果要查询某个key对应的值的时候要如何查询呢这里记录一种查询方法
json列的值 {“InventoryMainTypeCode”: 1, “InventoryMainTypeName”: “GOOD”}
现在要查询InventoryMainTypeCode为xxx或者InventoryMainTypeName为xxx的数据这里以springbootmybatis为例子
代码 请求类
Query query new Query();Data
public class Query implements Serializable {private MapString, Object featureMap new HashMap();public void setFeature(String feature) {if (StringUtils.isNotBlank(feature)) {featureMap JSON.parseObject(feature, Map.class);}}public void addFeature(String key, Object value) {if (StringUtils.isBlank(key)) {return;}this.featureMap.put(key, value);}public void addFeatureMap(MapString, Object featureMaps) {if (MapUtils.isNotEmpty(featureMaps)){this.featureMap.putAll(featureMaps);}}
}在代码中将key添加到Feature中
query.addFeature(DicConst.InventoryMainTypeCode.name(), 1);
ListResultDTO dTOS dictionaryManager.queryDicByParam(query);mapper文件 ListCnbDictionaryDO queryDicByParam(CnbDictionaryQuery query);xml: select idqueryDicByParam resultMapBaseResultMapselectinclude refidBase_Column_List/frominclude refidTable_Name/whereif testid ! nulland id #{id}/ifif testfeatureMap ! null and featureMap.size 0foreach collectionfeatureMap indexkey itemvalueif testvalue ! null![CDATA[and feature-$.${key} #{value}]]/if/foreach/if/where/select