mybatis之使用 my-batis 将返回类型转换为 bool 值

bjzhanghao 阅读:40 2024-08-19 10:31:18 评论:0

我目前正在使用以下映射:

@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
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号