【问题标题】:JPAUpdateClause - is it possible to concatenate string values when setting values?JPAUpdateClause - 设置值时是否可以连接字符串值?
【发布时间】:2018-08-14 16:33:31
【问题描述】:

我正在使用 JPAUpdateClause 更新所有满足 BooleanExpression where 子句的行。

BooleanExpression where = myEntity.id.isNotNull();
long updatedCount = update.where(where)
        .set(myEntity.comments, request.getComment())
        .execute();

myEntity.cmets 是一个字符串。

是否可以在调用 set() 时附加 request.getComment() 而不是替换现有值?

【问题讨论】:

  • 你想把它附加到什么地方?
  • 数据库中的现有评论。因此,如果在执行此查询之前数据库具有某些值,则新值只是添加到末尾。也许追加会是一个更好的询问方式

标签: java querydsl mysema


【解决方案1】:

不要输入request.getComment(),试试下面的方法

Expressions.operation(String.class, Ops.ADD, myEntity.comments, request.getComment())

【讨论】:

  • 您好 Ashishkumar,感谢您的帮助!我认为你的答案是正确的,但我是一回事。 Expressions.operation 的参数是 Type、Operator 和 Expression。我如何将 myEntity.cmets 和 request.getComments 这两个值表示为表达式?
猜你喜欢
  • 1970-01-01
  • 2021-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
相关资源
最近更新 更多