[英]Unwanted Json result using mybatis result with hashmap
my sqlmap.xml我的 sqlmap.xml
<select id="getList" resultType="hashmap">
SELECT A,B,C,D FROM MYTABLE
</select>
result example结果示例
A B C D
john 123 math 100
jade 456 math 78
janet 789 math 98
controller code控制器代码
@RequestMapping("/my/result.json")
public @ResponseBody List MyResult(){
return myDAO.getList();
}
but, json result is looking confused column sort such as,但是,json 结果看起来很混乱,例如列排序,
[
{"B":123,"C":"math","A":"john","D":100},
{"B":456,"C":"math","A":"jade","D":78},
{"B":789,"C":"math","A":"janet","D":98}
]
I want get result with sql with defined Column names and index.我想用定义了列名和索引的 sql 得到结果。 but in result, it's different column name index between sql and hashmap.
但结果是,sql 和 hashmap 之间的列名索引不同。 Any idea how to get json result same as sql result?
知道如何获得与 sql 结果相同的 json 结果吗?
To solve this issue, in sqlmap, just set the resultType
to java.util.LinkedHashMap
: 要解决此问题,请在sqlmap中将
resultType
设置为java.util.LinkedHashMap
:
<select id="getList" resultType="java.util.LinkedHashMap">
SELECT A,B,C,D FROM MYTABLE
</select>
I have the same issue.我有同样的问题。 I have set the resultType ="java.util.LinkedHashMap" already.
我已经设置了 resultType ="java.util.LinkedHashMap"。 But the list returned still out of order.
但是返回的列表仍然乱序。 Why?
为什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.