Room DAO Order By ASC or DESC variable

前端 未结 3 2268
半阙折子戏
半阙折子戏 2021-02-18 17:48

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:38

    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();
    

提交回复
热议问题