QueryDSL:如何选择文字作为 SQLSubQuery 的一部分? [英] QueryDSL: How to SELECT literals as part of a SQLSubQuery?

查看:273
本文介绍了QueryDSL:如何选择文字作为 SQLSubQuery 的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 QueryDSL SQL 实现 https://stackoverflow.com/a/16392399/14731?>

我明白

<块引用>

new SQLSubQuery().from(customer).where(customer.email.eq("foo@example.com"))

模型

<块引用>

select customer where customer.email = 'foo@example.com'

但我不明白如何选择[文字],例如:

select 1 from customer选择'foo@example.com', 0

根据上述链接的要求.

解决方案

如果可以使用参数,那么使用常量应该可以

new SQLSubQuery().from(customer).where(customer.email.eq("foo@example.com")).list(Expressions.constant("foo@example.com"),表达式.常量(0))

Expressions.constant 记录在此处 http://www.querydsl.com/static/querydsl/3.2.3/apidocs/com/mysema/query/support/Expressions.html#constant%28T%29

How do I implement https://stackoverflow.com/a/16392399/14731 using QueryDSL SQL?

I understand that

new SQLSubQuery().from(customer).where(customer.email.eq("foo@example.com"))

models

select customer where customer.email = 'foo@example.com'

but I don't understand how to select [literal] such as:

select 1 from customer or select 'foo@example.com', 0

as required by the aforementioned link.

解决方案

If it is ok to use parameters then using constants should work

new SQLSubQuery().from(customer)
  .where(customer.email.eq("foo@example.com"))
  .list(Expressions.constant("foo@example.com"),
        Expressions.constant(0))

Expressions.constant is documented here http://www.querydsl.com/static/querydsl/3.2.3/apidocs/com/mysema/query/support/Expressions.html#constant%28T%29

这篇关于QueryDSL:如何选择文字作为 SQLSubQuery 的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆