问题
I have the following DAO with a query:
@Dao
public interface BaseballCardDao {
@Query(
"SELECT * FROM baseball_cards " +
"WHERE brand LIKE :brand " +
" AND year = :year " +
" AND number LIKE :number " +
" AND player_name LIKE :playerName " +
" AND team LIKE :team"
)
LiveData<List<BaseballCard>> getBaseballCards(
String brand, int year, String number, String playerName, String team
);
}
The String
parameters are "optional" in the sense that I can pass "%%"
to match all rows due to the LIKE
operator. But I cannot do this with year
since it is an int
. One solution is to add two different @Query
methods, one with the int year
parameter and the other without. Is there a more elegant way to create an optional parameter with Room's @Query
?
来源:https://stackoverflow.com/questions/52029435/optional-query-parameters-for-android-room