如果字段发生变化 set get 方法(未显示)也要更新 否则找不到
@Entity(tableName = "marquee")
public class Marquee {
@PrimaryKey
private int marqueeid;
private String message;
private String startdate;
private String stopdate;
@Ignore
private int type;
private int status;
@Ignore
private List<MarqueeTime> playtimes;
插入
<!-- 单个插入 -->
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertMarquee(Marquee marquee);
<!-- 批量插入 -->
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<Marquee> marquees);
更新
<!-- 更新对象 -->
@Update(onConflict = OnConflictStrategy.REPLACE)
void updateMarquee(Marquee marquee);
<!-- 更新某个字段 -->
@Query("update marquee set message=:msg where marqueeId=:id")
void update(String msg,int id);
删除
<!-- 删除单个 -->
@Delete
void deleteMarquee(Marquee marquee);
<!-- 条件删除 -->
@Query("delete from marquee where marqueeId=:id")
void deleteMarquee(int id);
<!-- 删除集合 -->
@Delete
void deleteAll(List<Marquee > marquees);
<!-- 删除全部 -->
@Query("delete from marquee")
void deleteAllMarquees();
查询
//有效日期内的检索
@Query("select * from marquee where date(:currentDate) between date(startDate) and date(stopDate) and status =0")
List<Marquee> queryValidMarquee(String currentDate);
<!-- 根据某个字段升序 -->
@Query("select * from marquee order by marqueeId asc")
LiveData<List<Marquee>> loadMarquees();
<!-- 限定查询数量 -->
@Query("select * from ward limit 1")
LiveData<Marquee> loadMarquee();
<!--比较查询 -->
@Query("select * from marquee where marqueeId in (:ids)")
List<Marquee> getMarqueeById(String... ids);
网友评论