Vertical table data processing method

As we all know, the vertical table is easy to expand, but the data is not intuitive, it is more troublesome to apply, the horizontal table is easy to understand, and the data is easy to process, but if you add fields, you need to modify the database. The two have different application scenarios, please refer to my other article for details:

https://blog.csdn.net/hanruikai/article/details/79730028


When designing the credit card module, since the credit card filter conditions need to be configured to facilitate flexible expansion, the vertical table processing method is adopted. The structure is as follows:


The parameter key is the filter condition.

During data processing, such as reading all credit card information and configuration parameters, use map storage, key is credit id, value is a map, used to store parameters.

Special logic processing can be performed on a key alone, such as splitting the value.

Finally, traverse the map, the key is the credit card id, the front end does not care, remove this layer, put the map as the value pair into the list, and return to the front end

for (CreditCardInfoAndParam creditCardInfoAndParam : creditCardInfoAndParamList) {
            if (!creditIdList.contains(creditCardInfoAndParam.getId())) {
                creditIdList.add(creditCardInfoAndParam.getId());
            }
            JSONObject paramJson = json.getJSONObject(creditCardInfoAndParam.getId().toString());
            if (paramJson == null) {
                paramJson = new JSONObject();
                paramJson.put("creditCardName", creditCardInfoAndParam.getCreditCardName());
                paramJson.put("creditCardOrder", creditCardInfoAndParam.getCreditCardOrder());
                paramJson.put("state", creditCardInfoAndParam.getState());
                paramJson.put("bankId",creditCardInfoAndParam.getBankId());
            }
            if (creditCardInfoAndParam.getParamKey().equalsIgnoreCase(Constants.BRIGHT_SPOT)){
                paramJson.put(creditCardInfoAndParam.getParamKey(), creditCardInfoAndParam.getParamValue().split(","));
            }
            else {
                paramJson.put(creditCardInfoAndParam.getParamKey(), creditCardInfoAndParam.getParamValue());
            }
            json.put(creditCardInfoAndParam.getId().toString(), paramJson);
        }
        for (Long id:creditIdList){
            creditCardArray.add(json.getJSONObject(id.toString()));
        }
jsonobject is actually a map, jsonarray is a list


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325405930&siteId=291194637