coalesce函数-返回参数中第一个非null值

by admin on 2019年9月3日

Coalsece 重返第三个不是null的值

  

select top 5 [objname]

      ,[objjc]

      ,[objorder]

      ,[objid]

      ,[parentid]

      ,[grade]

      ,[type]

      ,[href]

      ,coalesce( [rel],0) rel

      FROM [Menu]



  select top 5 [objname]

      ,coalesce( [rel],'0') rel

      FROM [Menu]

     order by NEWID()



       select top 5 [objname]

      , rel

      FROM [Menu]

     order by NEWID()

 

coalesce函数-再次来到参数中首个非null值

数据库中从未满意条件的id 就能够报
HTTP Status 500 – Request processing failed; nested exception is
org.apache.ibatis.binding.BindingException: Mapper method
‘org.tsinghua.cis.dao.CisMedicineDetailsIdDao.findMedicineDetailsIdByClinicIdAndBarCode
attempted to return null from a method with a primitive return type
(int).

只要后台在数量为空的时候利用了暗许的回到值–NULL,那大家怎么来拍卖呢?
有三种格局,看本人爱怜挑一种就好了.
1.和后台讲,叫他归来字符串空.
2.用AFN的自行把空替换为nil,代码如下:
AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
//自动去除空值
AFJSONResponseSerializer *response = [AFJSONResponseSerializer
serializer];
response.removesKeysWithNullValues = YES;
session.responseSerializer = response;
3.融洽加剖断
![array[@”data”] isEqual:[NSNull null]];//不为Null
4.用第三方的转模型工具,会把null 转为nil.
5.还能接纳第三方库NullSafe.
//丰俭由人,本人好好选吧.

学习了:

   <select id="findMedicineDetailsIdByClinicIdAndBarCode" resultType="int">
       <![CDATA[
        SELECT
          a.`id`
        FROM
          `cis_medicine_details_id` AS  a
        INNER JOIN
          `cis_medicine_pricing` AS b
        ON
          a.id = b.medicine_details_id
        WHERE
          `medicine_bar_code` = ${medicineBarCode}
        AND
          `clinic_id` = ${clinicId}
        ]]>
    </select>

本条要复杂一些:

斩草除根方案

 

1.把resultType=”int” 改为resultType=”Integer”

在server层 判断 if(null==参数){
做相应的操作 是赋值0还是重回null 依据须求活动编排
}

2.使用IFNULL函数

   <select id="findMedicineDetailsIdByClinicIdAndBarCode" resultType="int">
       <![CDATA[
        SELECT
          IFNULL(a.`id`,0)
        FROM
          `cis_medicine_details_id` AS  a
        INNER JOIN
          `cis_medicine_pricing` AS b
        ON
          a.id = b.medicine_details_id
        WHERE
          `medicine_bar_code` = ${medicineBarCode}
        AND
          `clinic_id` = ${clinicId}
        ]]>
    </select>

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图