How does the Map queried by Spring JdbcTemplate generate a case-ignoring Key? (Turn)

Original address: How does the Map queried by Spring JdbcTemplate generate a case-ignoring Key?

Original discussion group: How does a Map queried with Spring JdbcTemplate generate a case-ignoring Key?

 

Java is case-sensitive, ordinary Map such as HashMap if the key="ABC" value="XXX" in it,
then map.get("Abc") or map.get("abc") is not worth getting.

But Spring generates a case-ignoring map, which makes me curious.
For example, jdbcTemplate.queryForList(sql) generates List<Map>
key="BID" value="STR1"

where the keys are all uppercase,
but if
System. out.println("map.get(BILLIDS):" + map.get("BID") );
System.out.println("map.get(billids):" + map.get("bid") );
System.out.println("map.get(bIlLIds):" + map.get("bId") );
can be found =STR1

How is this done?

 

Spring uses its own encapsulated Map: org.springframework.util.LinkedCaseInsensitiveMap, which is encapsulated based on java.util.LinkedHashMap.

LinkedCaseInsensitiveMap has a member variable Map caseInsensitiveKeys, the mapping relationship between the lowercase Key and the real key. When getting, first convert the key you passed in to lowercase to get the real KEY, and then get the corresponding value, so the case is not sensitive.
But in fact, the key is still in its original color, so if it is serialized to json or xml format, the key is uppercase, which needs attention.

 

  public Object put(String key, Object value)
    {
        caseInsensitiveKeys.put(convertKey(key), key);
        return super.put(key, value);
    }

    public Object get(Object key)
    {
        if(key instanceof String)
            return super.get(caseInsensitiveKeys.get(convertKey((String)key)));
        else
            return null;
    }

Guess you like

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