By default, when resultType="" the returned key values are all capitalized.
Now if you want to change the key to what you want, just add an alias to the fields you query.
like:
<select resultType=""> select as "sName", as "sSex" from student </select>
Double quotes after as are critical, otherwise they won't work.
Supplementary knowledge:mybatis returns the map key value case deduplication, CaseInsensitiveMap and LinkedCaseInsensitiveMap source code
I encountered a problem when writing a project today:
Written is a set of completely decoupled modules for dynamically splicing SQL using freemarker templates
However, the spliced SQL can only use LinkedHashMap to return the result set to ensure the order of the data. However, when the data is output, mybatis returns data with the same key but different upper and lower cases.
When processing this data, I first chose to use the same value value to process, but some data have the same value value but different keys
It seems that I can only use keys to process. First, I used CaseInsensitiveMap to put the linkedHashMap data into CaseInsensitiveMap.
The result does have the effect of deduplication when outputting, but when exporting Excel, it must correspond to the header header header. The order of mybatis query corresponds to the header header, but the order of extraction is not the corresponding.
Therefore, the data can only be corresponded through sorting, but if you sort, you can only use LinkedHashMap to remember the order
Therefore, after querying the information, I found LinkedCaseInsensitiveMap
LinkedCaseInsensitiveMap inherits LinkedHashMap, which can detect the uniqueness of keywords (case insensitive), so the ok bug is perfectly solved.
Attach LinkedCaseInsensitiveMap source code
package ; import ; import ; import ; import ; import ; import ; public class LinkedCaseInsensitiveMap<V> extends LinkedHashMap<String, V> { private Map<String, String> caseInsensitiveKeys; private final Locale locale; public LinkedCaseInsensitiveMap() { this((Locale)null); } public LinkedCaseInsensitiveMap(Locale locale) { = new HashMap(); = locale != null?locale:(); } public LinkedCaseInsensitiveMap(int initialCapacity) { this(initialCapacity, (Locale)null); } public LinkedCaseInsensitiveMap(int initialCapacity, Locale locale) { super(initialCapacity); = new HashMap(initialCapacity); = locale != null?locale:(); } public V put(String key, V value) { String oldKey = (String)((key), key); if(oldKey != null && !(key)) { (oldKey); } return (key, value); } public void putAll(Map<? extends String, ? extends V> map) { if(!()) { Iterator var2 = ().iterator(); while(()) { Entry entry = (Entry)(); ((String)(), ()); } } } public boolean containsKey(Object key) { return key instanceof String && (((String)key)); } public V get(Object key) { if(key instanceof String) { String caseInsensitiveKey = (String)(((String)key)); if(caseInsensitiveKey != null) { return (caseInsensitiveKey); } } return null; } public V getOrDefault(Object key, V defaultValue) { if(key instanceof String) { String caseInsensitiveKey = (String)(((String)key)); if(caseInsensitiveKey != null) { return (caseInsensitiveKey); } } return defaultValue; } public V remove(Object key) { if(key instanceof String) { String caseInsensitiveKey = (String)(((String)key)); if(caseInsensitiveKey != null) { return (caseInsensitiveKey); } } return null; } public void clear() { (); (); } public Object clone() { LinkedCaseInsensitiveMap copy = (LinkedCaseInsensitiveMap)(); = new HashMap(); return copy; } protected String convertKey(String key) { return (); } }
The above article mybatis returns the operation of changing the Map type key to lowercase is all the content I share with you. I hope you can give you a reference and I hope you support me more.