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

标签 mybatis spring-mybatis

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

@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/

相关文章:

java - Mybatis 嵌套集合不能正确使用列前缀

orm - 如何在MyBatis中使用带注释的动态SQL查询(如何使用selectProvider)?

java - MyBatis 将结果映射到 MyBatisRepository 中的 List<String>

java - 如果我在 MyBatis 的 <resultMap> 中定义 <association>,即使属性与列名匹配,我是否也必须定义所有字段?

MyBatis - 获取多个集合

java - 准备好的语句需要重新准备

mysql - 数据库执行结果和mybatis执行结果不一致

java - 在 MyBatis 中返回一个列表<MyClass>

java 和 mybatis - 误解一对多关系 - 仅注释

java - 如何使用 MyBatis 创建 alter table 语句? MySQLSyntaxErrorException : You have an error in your SQL syntax