我目前正在使用以下映射:
@Select ("select count(*) from something where id = 2344")
int userExists();
但是我想要这样的东西:
@Select ("select count(*) from something where id = 2344")
boolean userExists();
我可以将 0 转换为 false 并将所有 > 0 转换为 true 吗?
我正在使用 Oracle。因此,我希望 my-batis 提供某种返回类型映射。
最佳答案
以下是如何在 Oracle 中使用 case 语句返回 bool 值:
@Select ("select case when count(*) > 0 then 1 else 0 end result from something where id = 2344")
boolean userExists();
希望对您有所帮助。
关于mybatis - 使用 my-batis 将返回类型转换为 bool 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32733486/