【问题标题】:Why bind variables amount isn't valid?为什么绑定变量数量无效?
【发布时间】:2021-07-30 21:49:57
【问题描述】:

我正在像这样覆盖 CQL 语句:

    @Query("INSERT INTO message (content,email,magic_number,title) VALUES (?, ?, ?, ?);")
    Message save(Message message);

但是 Spring 会抛出无效数量的绑定变量。

这里有什么问题?


编辑:

我正在添加消息类:

@Table(value = "message")
@Data
@NoArgsConstructor(force = true)
@AllArgsConstructor
public class Message {

    @Column("email")
    private String email;

    @Column("title")
    private String title;

    @Column("content")
    private String content;

    @PrimaryKey
    @Column("magic_number")
    private int magicNumber;
}

还有 json whitch 被发送到 api:

{
    "email": "name@example.com",
    "title": "title",
    "content": "text123",
    "magic_number": 101
}

【问题讨论】:

  • 另加Message类代码
  • @MDRuhulAmin 完成。

标签: java cassandra cql spring-data-cassandra


【解决方案1】:

Spring 期望 4 个绑定变量与您在查询中指定的 4 个绑定标记 (?) 对齐。

要使其工作,您必须将 4 个输入参数添加到 save() 方法。

如果您扩展 CassandraRepository,则保存方法已经为您实现。您是否有理由尝试覆盖它?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-11
    • 2015-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多