JPA中的JpaRepository接口的使用

 SpringData的所有接口

CrudRepository接口 ,其中提供了这些方法提供使用,同时继承了其父接口的方法

 其中saveAndFlush()方法就相当于hibernate中的saveOrUpdate()和JPA中的merge()

	@Test
	public void JpaRepository() {
		Person person = new Person();
		person.setId(27);
		person.setName("ab");
		person.setAge(22);
		person.setEmail("[email protected]");
		//该方法就相当于hibernate中的saveOrUpdate()和JPA中的merge()
		personRepositoiry.saveAndFlush(person);
	}

该接口提供了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);//删除一个实体集合

猜你喜欢

转载自blog.csdn.net/qq_36722039/article/details/81147219
今日推荐