Room DAO Order By ASC or DESC variable

前端 未结 3 1643
旧时难觅i
旧时难觅i 2021-02-18 18:08

I\'m trying to make a @Query function in my @Dao interface which has a boolean parameter, isAsc to determine the order:

@Q         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-18 18:30

    Create two queries, one with ASC and one with DESC.

    @Query("SELECT * FROM Persons ORDER BY last_name ASC")
    List getPersonsSortByAscLastName();
    
    @Query("SELECT * FROM Persons ORDER BY last_name DESC")
    List getPersonsSortByDescLastName();
    

提交回复
热议问题