示例:
@Entity(tableName = "user") public class User { @PrimaryKey(autoGenerate = true) public int id;
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "age")
public int age;
}
@Dao
public interface UserDao {
@Query("SELECT * FROM user WHERE age=:age")
List
// ...其他的查询操作...
}
@Database(entities = {User.class}, version = 1) public abstract class AppDatabase extends RoomDatabase { public abstract UserDao userDao(); }
示例:
int age = 18;
List
示例:
List
示例:
List
注意事项:
请确保查询条件的语法正确,包括查询语句和参数,错误的语法可能会导致查询失败或返回无效结果。同时,也要确保表格中的数据符合预期,例如不存在年龄为负数的用户等。