QueryDSL: How to SELECT literals as part of a SQLSubQuery?

人走茶凉 提交于 2019-12-11 02:58:32

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/18691317/querydsl-how-to-select-literals-as-part-of-a-sqlsubquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!