Android房间从列中查找行

Android房间从列中查找行,android,kotlin,android-room,Android,Kotlin,Android Room,在我的表中,我有一列ID,我存储了一个ID列表。为了保存它,我需要输入转换器 class IdsConverter { @TypeConverter fun storedStringToMyObjects(data: String?): List<Long?>? { if (data == null) { return Collections.emptyList() } val listType:

在我的表中,我有一列ID,我存储了一个ID列表。为了保存它,我需要输入转换器

class IdsConverter {
    @TypeConverter
    fun storedStringToMyObjects(data: String?): List<Long?>? {
        if (data == null) {
            return Collections.emptyList()
        }
        val listType: Type = object : TypeToken<List<Long?>?>() {}.type
        return Gson().fromJson(data, listType)
    }

    @TypeConverter
    fun myObjectsToStoredString(myObjects: List<Long?>?): String? {
        if (myObjects == null || myObjects.isEmpty()) {
            return ""
        }
        return Gson().toJson(myObjects)
    }
}

如果您真的想将ID保存在一行的一列中作为json,那么使用sqlite将更为方便,因为您需要一个类似sqlite的自定义构建(并且您将获得其他一些好处) 您可以找到包含select查询的示例

但您的解决方案似乎有效:)


您还有其他选择:将每个id保存在新行。

您解决了问题吗?
select *  FROM  test WHERE  (ids LIKE '%2,%' or ids LIKE '%,2,'or ids LIKE '%2' or ids = '2' or ids like '2,%')