简体   繁体   中英

Grails Create Critera and Listing single or specified column/s value only?

I grails im trying to fetch a lookup value from the database and i want to list a list of single column value that is "Value" column .

    private Static Final String Custom = "Custom"  //lie in class Constants

    LookUp.createCriteria.list() { 

    eq('type',LookupTypeEnum.valueOf(Constants.Custom).toString())



   }

this listing was like select ,

how can i make this query into

   Select Value from LookUp where Type = 'Custom' 

i want my grails query to return me a single query result like the sql. I want to bind it to a list box?

My bad this do all the trick , private Static Final String Custom = "Custom" //lie in class Constants //LookupTypeEnum is Enum collection implementation class if don't have it simply you can replace it with your value ="Custom" or a variable Constants.Custom

  LookUp.createCriteria.list() { 
  eq('type',LookupTypeEnum.valueOf(Constants.Custom).toString())
  projections {  //projection does the trick
   property('value')
 }

}

It's equivalent SQl select query is :

select value from lookup where type='custom' ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM