【发布时间】:2017-11-08 08:17:55
【问题描述】:
我正在创建 API,它以JSON 格式向客户端发送响应。
我在做什么,我在Mysql DB 中有一个表,其中有一个主键。客户端使用该主键作为参数请求数据,我使用hibernate 从数据库中获取数据并作为响应发送回客户端。
我的 SQL 查询:
select * from emp_table Where id = 202
在 JSON 响应中,我将发送表的所有列,如上述查询中所示。到这里我的代码工作正常。
但现在我正在使用case statement 生成一个新列,如以下查询所示:
select *, (case when sal > 4.5 then 'Yes' else 'No' end) as bp_status from emp_table Where id = 202
如何在JSON 响应中发送这个新的bp_status 列??
我尝试使用 @Formula 但无法正常工作
@Formula(value = "(case when sal > 4.5 then 'Yes' else 'No' end)")
private String bp_status;
【问题讨论】:
标签: hibernate jakarta-ee hibernate-annotations