【问题标题】:Ignore field for update in spring-r2dbc忽略 spring-r2dbc 中的更新字段
【发布时间】:2020-09-02 10:49:52
【问题描述】:

我正在使用 spring r2dbc 和 ReactiveCrudRepository,我有一个字段需要在生成更新查询时忽略

@Data
@Table(PRODUCT_TABLE)
public class ProductEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) // Id generated by database
    private Integer id;

    private Integer companyId;

    @Column(insertable=false, updatable = false)
    private String companyName;

    @NotBlank
    private String name;

    private VerificationStatus verificationStatus;
}

如何在更新查询中忽略 companyName。我可以使用@column 在插入查询中忽略它,但它不适用于更新

【问题讨论】:

    标签: java spring-webflux spring-data-r2dbc r2dbc


    【解决方案1】:

    如果您不想保留该字段以供更新和插入,则将该字段标记为@Transient

    例如,

    @Transient
    private String companyName;
    

    https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/annotation/Transient.html

    【讨论】:

    • 但我确实想将它用于选择语句,在瞬态的情况下它将被忽略
    【解决方案2】:

    简化使用

    @ReadOnlyProperty
    

    例如,

    @ReadOnlyProperty
    private String companyName;
    

    https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/annotation/ReadOnlyProperty.html

    【讨论】:

      猜你喜欢
      • 2018-06-24
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 2016-11-02
      • 1970-01-01
      • 2015-10-13
      相关资源
      最近更新 更多