android - 如何在房间dao查询中连接字符串?

标签 android android-room android-architecture-components

我在查询中使用了 LIKE 运算符

 @Query("SELECT * FROM item where barcodes LIKE :barcode")
 List<Item> getItemWithBarcode(String barcode);

有什么方法可以将某些内容(appendedTxt) 添加到条形码?像这样

@Query("SELECT * FROM item where barcodes LIKE (:barcode + 'appendedTxt')")
List<Item> getItemWithBarcode(String barcode);

最佳答案

||运算符是“连接” - 它将其操作数的两个字符串连接在一起。 Docs

@Query("SELECT * FROM item where barcodes LIKE (:barcode || 'appendedTxt')")

List<Item> getItemWithBarcode(String barcode);

编辑:将双引号改为单引号

关于android - 如何在房间dao查询中连接字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52496281/

相关文章:

android - E/SQLiteLog : (283) recovered frames from WAL file

android - 如何在多个 ViewModel 之间共享 LiveData?

java - 保存多个警报实例

android - Android版本不断因Room和Kapt失败而失败:app:kaptDebugKotlin

Android Room - 自动生成主键

android - @Ignore 如何在带有 Room 的数据类中工作

android - 使用实时数据更新字符串值

android - 如何使用minifyEnable编译生产apk和使用minifyEnable false测试apk?

java - 有没有更理想的发送绘图命令的方式?

Android Toolbar actionLayout of Switch导致菜单按下时文本跳转