mybatis Long类型传值为0时bug记录

在mbatis中使用Xml配置sql语句时,出现了这样一个问题。当我传入的参数为0时候不会加条件判断语句,若为其他值就是正常的,然后发现是因为传入数值0去做判断时,mybatis会把参数0当成是空字符串去判断而引起查询结果错误。下面是我之前配置的sql语句:

<if test="pd.pid != null  and pd.pid != ' ' ">
   and pid=${pd.pid}
</if>

解决办法:
当传入的参数有0时,只判断!=null即可,所以去掉【pd.pid != ‘’ 】,因此Integer,Double,Float数值类型的同样如此

一个身份证地址解析出省市区的工具类

package com.javalaoniu.tool.utils;

 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

 /**
  * 身份证地址提取省市区工具类
  */
 public class AddressResolutionUtil {

     /**
      * 根据身份证地址提取省市区工具类
      *
      * @param address
      * @return
      */
     public static List<Map<String, String>> addressResolution(String address) {
         String regex = "(?<province>[^省]+自治区|.*?省|.*?行政区|.*?市)(?<city>[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?<district>[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)?(?<town>[^区]+区|.+镇)?(?<detail>.*)";
         Matcher m = Pattern.compile(regex).matcher(address);
         String province = null, city = null, district = null, town = null, detail = null;
         List<Map<String, String>> table = new ArrayList<Map<String, String>>();
         Map<String, String> row = null;
         while (m.find()) {
             row = new LinkedHashMap<String, String>();
             province = m.group("province");
             row.put("province", province == null ? "" : province.trim());
             city = m.group("city");
             row.put("city", city == null ? "" : city.trim());
             district = m.group("district");
             row.put("district", district == null ? "" : district.trim());
             town = m.group("town");
             row.put("town", town == null ? "" : town.trim());
             detail = m.group("detail");
             row.put("detail", detail == null ? "" : detail.trim());
             table.add(row);
         }
         return table;
     }
     public static void main(String[] args) {
         System.out.println(addressResolution("广东省深圳市福田区梅林街道办事处国际金融科技大厦"));
         System.out.println(addressResolution("山东省德州市禹城市伦镇堂子街村235号"));
     }
 }

DecimalFormat的计算 #和0的区别

@Test
public void testDecimalFormat() {
    System.out.println(format("####.##", new BigDecimal("0012.00")));// 12
    System.out.println(format("0000.00", new BigDecimal("0012.00")));// 0012.00
    System.out.println(format("#00.00", new BigDecimal("0012.00")));// 12.00
    System.out.println(format("000.00", new BigDecimal("0012.00")));// 012.00
    System.out.println(format("#.00", new BigDecimal("0012.00")));// 12.00
    System.out.println(format("0.00", new BigDecimal("0012.00")));// 12.00
}

瀚高数据库的时间比较

 SELECT
            COUNT (1)
        FROM
            (
                select
                    (

                        CASE
                            WHEN b.type = 0 then '自住户' WHEN b.type = 1 then '租户' WHEN b.type = 4 then '常客' else '其他'
                            end
                        ) "type"
                from
                    zhsq_housing_information b
                        left join zhsq_user_info a on
                        b.user_id = a.id
                where to_char (to_Date(b.create_time,'yyyy-MM-dd  HH24:mi:ss'),'yyyy-MM-dd')  between to_char (to_Date(#{startTime},'yyyy-MM-dd  HH24:mi:ss'),'yyyy-MM-dd')
        and  to_char (to_Date(#{endTime},'yyyy-MM-dd  HH24:mi:ss'),'yyyy-MM-dd')
            )

to_char (to_Date(b.create_time,'yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd') between to_char (to_Date(#{startTime},'yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd')

    and  to_char (to_Date(#{endTime},'yyyy-MM-dd  HH24:mi:ss'),'yyyy-MM-dd')
        )

瀚高数据库group by分组函数如何把字段空串空列归为一类

函数:

select 
     
            count ( 
                1
            ) ,
            COALESCE(NULLIF(trim(native_place),''),'其他') AS native_place
        from 
            zhsq_user_info 
        where 
            is_delete = '0' 
            and 
                to_char (to_Date(create_time,'yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd') 
                 between to_char (to_Date(${startTime},'yyyy-MM-dd  HH24:mi:ss'),'yyyy-MM-dd') and  
                 to_char (to_Date(${endTime},'yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd')
        group by 
            COALESCE(NULLIF(trim(native_place),''),'其他')

COALESCE函数:
当列是空列,就转换为其他数值

NULLIF函数:
当列是空串,就转换为其他数值