4

关于Spring List 返回给前端后,顺序不对了

 2 years ago
source link: https://www.oschina.net/question/3385909_2324663
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

关于Spring List 返回给前端后,顺序不对了

行者爷爷 发布于 今天 17:02

各位大佬,问个java基础的问题
外面定义了个map,
循环里,取每个字典的列表,tree
并把tree,放入map中,
原来是没有被我圈起来的代码,
但是,把这个MAP返回给前端时,tree里面的顺序竟然发生变化了,查的时候sql按指定字段order by 了,断点看,在放入map前顺序是正确的,但就是返回给前端后,就不行了。

最后不行就加了圈住部分的代码(n年前遇到过类似问题,就是这么解决的😂),map里不再放tree对象了,改放dictList了,问题解决了,
想问问各位大佬,这种现象作何解释。
这个问题在很早之前,刚参加工作时,遇到过一次,当初是把List转成了ArrayList解决的,但当时没追究为什么,过了几年了,又让遇到这种问题了,就想追究一下,为什么会出现这种情况,自己也写代码尝试了,重现不了


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK