返回boolean的mybatis查询
2024-09-03 12:15:33
注意:返回数量为0时函数返回值为false,返回数量为非零值时为true。
Java函数:
boolean hasSameServiceCode(@Param("oldDepotCd") String oldDepotCd,@Param("newDepotCd") String newDepotCd);
XML代码:
<select id="hasSameServiceCode" resultType="java.lang.Boolean">
select (case when count(*)=1 then 1 else 0 end) as cnt from (
select distinct s.service_code
from depot d inner join service_carrier_mapping s
on d.carrier_code=s.handling_carrier_code
where exists (select null from DEPOT where depot_code=#{oldDepotCd})
and exists (select null from DEPOT where depot_code=#{newDepotCd})
and d.depot_code in (#{oldDepotCd},#{newDepotCd}) )
</select>
取值:
cnt=1,返回true
cnt=0,返回false
注意,如果直接写select count(*) from XXX,因为会有0,1, >1三种情况,如果是0,返回值是false,这个没有争议;如果是1,返回值为true;如果是>1,返回值也为true。非零值都是true,这个是我实测了的,并不像网文 https://blog.csdn.net/qq_39039017/article/details/80700002 所说的只有1返回true,0和大于1的值都返回false。
像我上面的业务,只能在返回1时返回真,返回0或者其它值都得返回假,这就需要用case语句来转化一下。
--2020-04-07--
最新文章
- [Android Pro] ScrollView嵌套RecyclerView时滑动出现的卡顿
- html局部打印
- Spring任务调度器之Task的使用
- (转)Hibernate事务管理
- Mac添加bash alias
- JDBC-java访问数据库
- freeCodeCamp:Factorialize a Number
- lstm的debug模式下编译不行貌似
- Collection Views and Building Custom Layouts-备
- 类似QtiPlot的veusz,sigmaplot,pymol
- Python爬虫小白---(二)爬虫基础--Selenium PhantomJS
- 浅谈 HTML5plus 开发移动应用
- c#枚举位运算操作
- golang 安装tensorflow
- vue 饿了么项目笔记
- (转)适用微信小程序的table表格(带隔行变色)
- 关于JSON call 的一个小问题
- [No000014D]chrome console 调试 引入 jquery等外部库
- You Don&#39;t Know JS: Scope &; Closures (第3章: 函数 vs 块作用域)
- 利用WordPress REST API 开发微信小程序从入门到放弃
热门文章
- PyTorch 学习
- ECS7天实践进阶训练营Day1:使用阿里云ECS,快速搭建、管理VuePress静态网站
- MyBatisPlus性能分析插件,条件构造器,代码自动生成器详解
- 【API进阶之路】帮公司省下20万调研费!如何巧用情感分析API实现用户偏好调研
- [leetcode/lintcode 题解] 有效回文 II &#183; Valid Palindrome II
- scss @mixin &; @include
- LeetCode 115.不同的子序列 详解
- windows安装cnpm步骤
- CSS动画实例:Loading加载动画效果(一)
- Android studio 在项目里配置签名 + cmd命令安装apk在测试机