Created
October 14, 2013 15:54
-
-
Save pabloalba/6977872 to your computer and use it in GitHub Desktop.
Get a list of ids, and show the elements. This code is too damn long for this simple task. Improvements?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def showContents(){ | |
def contents = [] | |
def ids = params.list('id').findAll { it.isLong() }*.toLong() | |
if (ids) { | |
contents = Content.createCriteria().list { | |
'in' 'id', ids | |
} | |
} | |
render view:'showContents', model:[contents:contents] | |
} |
Ohhhhh, acabo de hacer la prueba y no funciona (al menos en 2.1.5)
Si no funciona el metodo "getAll" puedes usar "findAllByIdInList" que debería comportarse igual
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
En lugar de hacer el criteria puedes poner:
Otra mejor sería comprobar qué ocurre si la lista de
ids
es vacía, por lo que a lo mejor te podrías ahorrar el if y demás y dejar el código así: