我的实体
public class CarModelEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "model_id")
private Integer modelId;
@Column(name = "model_name")
private String modelName;
@Column(name = "is_parent")
private Integer isParent;
@Column(name = "parent_id")
private Integer parentId;
@Column(name = "created_by")
private Integer createdBy;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
}
我的代码:
CarModelEntity data = carModelRepo
.saveAllAndFlush(CarModelEntity.builder()
.isParent(1)
.modelName(value)
.build());
语法错误:
Error:(49, 25) java: method saveAllAndFlush in interface org.springframework.data.jpa.repository.JpaRepository<T,ID> cannot be applied to given types;
required: java.lang.Iterable<S>
found: com.*****.catprices.mobileapp.model.entity.CarModelEntity
reason: cannot infer type-variable(s) S
(argument mismatch; com.****.catprices.mobileapp.model.entity.CarModelEntity cannot be converted to java.lang.Iterable<S>)
我的存储库:
public interface CarModelRepo extends JpaRepository<CarModelEntity, Integer> {
}
1条答案
按热度按时间wbgh16ku1#
作为答案转发
saveAllAndFlush接受Iterable对象当你给予简单的Object时,你可以把你的CalModelEntity添加到一个实现Iterable的Object中,比如ArrayList,HashMap等等,然后把Object传递给saveAllAndFlush方法。并且saveAllAndFlush还返回Object的List,所以你需要一个List来接收来自方法的返回值。
下面是一些示例代码
以下是一些参考链接:
IterableJpaRepository显示器