简体   繁体   English

使用CrudRepository的保存

[英]Using CrudRepository's save

Using 使用

org.springframework.data.repository.CrudRepository
<S extends T> S save(S entity);

What is the difference between these two: 两者之间有什么区别:

entity = crudRepository.save(entity)
crudRepository.save(entity)

Re-referencing the variable to the save()'s return value seems unnecessary. 似乎没有必要将变量重新引用为save()的返回值。

The snippet entity = crudRepository.save(entity) is used when you want to get back the saved entity to perform further operations depending on it. 当您要取回保存的实体以根据其执行进一步的操作时,将使用片段entity = crudRepository.save(entity)

The documentation reads: 文档的内容如下:

Saves a given entity. 保存给定的实体。 Use the returned instance for further operations as the save operation might have changed the entity instance completely. 将返回的实例用于进一步的操作,因为保存操作可能已完全更改了实体实例。

entity = crudRepository.save(entity) 实体= crudRepository.save(实体)

Allow you to get back the id generated if you save a new entity. 如果您保存新实体,则可以取回生成的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM