Update some specific field of an entity in android Room

前端 未结 7 1620
臣服心动
臣服心动 2020-11-29 16:45

I am using android room persistence library for my new project. I want to update some field of table. I have tried like in my Dao -

// Method 1         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 17:48

    You could try this, but performance may be worse a little:

    @Dao
    public abstract class TourDao {
    
        @Query("SELECT * FROM Tour WHERE id == :id")
        public abstract Tour getTour(int id);
    
        @Update
        public abstract int updateTour(Tour tour);
    
        public void updateTour(int id, String end_address) {
            Tour tour = getTour(id);
            tour.end_address = end_address;
            updateTour(tour);
        }
    }
    

提交回复
热议问题