Grails mapping sort on multiple fields :: Groovy sort on multiple map entries

后端 未结 3 2005
生来不讨喜
生来不讨喜 2020-12-09 09:53

Stumped on this one. In Grails it seems one cannot define a default sort on multiple columns in domain mapping a la static mapping = { sort \'prop1 desc, prop2 asc\' }, or

3条回答
  •  北海茫月
    2020-12-09 10:29

    Here is a Groovy solution. Still essentially implementing a Comparator though.

    list.sort { map1, map2 -> map1.rowNum <=> map2.rowNum ?: map1.position <=> map2.position }
    

提交回复
热议问题