JpaRepository接口

JpaRepository

  • 提供了JPA相關功能
 List<T> findAll(); //查找所有實體 
List<T> findAll(Sort sort); //排序、查找所有實體 
List<T> save(Iterable<? extends T> entities);//保存集合 
void flush();//執行緩存與數據庫同步 
T saveAndFlush(T entity);//強制執行持久化 
void deleteInBatch(Iterable<T> entities);//刪除一個實體集合 
 @Test
   public void testJpaRepository(){
       Person person = new Person();
       person.setBrith(new Date());
       person.setEmail("[email protected]");
       person.setName("xcv");
       //person.setId(3);
       //當數據不存在即不設置id時 執行添加操作 
       personRepsotory.saveAndFlush(person);
   }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章