遇到过的那些坑

###1.事务要慎用

  • 更新单条记录不需要使用事务
  • 避免在事务中做复杂的业务处理,事务中最好只包括数据更新操作
  • 避免使用全局拦截式事务,容易产生长事务
  • 事务只对同一连接生效,多数据源事务需要额外考虑

###2.关于特殊字符的处理

// 普通字符, 数字字母空格反斜杠
String s6 = "ZHA/NG SAN";
System.out.println(Pattern.compile("[0-9a-zA-Z_ /]+").matcher(s6).matches());
System.out.println(Pattern.compile("([0-9a-zA-Z_]|[ /])+").matcher(s6).matches());
// 普通字符, 数字字母下划线
String s = "123abcAZY_";
System.out.println(Pattern.compile("\\w+").matcher(s).matches());
System.out.println(Pattern.compile("[0-9a-zA-Z_]+").matcher(s).matches());
// 非普通字符
String s2 = "@$%^中国";
System.out.println(Pattern.compile("\\W+").matcher(s2).matches());
System.out.println(Pattern.compile("[^0-9a-zA-Z_]+").matcher(s2).matches());
// 中文字符, 不包括标点
String s3 = "中國";
System.out.println(Pattern.compile("[\\u4e00-\\u9fa5]+").matcher(s3).matches());
// 其它特殊字符
String s4 = "\u00b7\u3002\uff0c\uff0e"; // ·。,.
System.out.println(Pattern.compile("[^0-9a-zA-Z_\\u4e00-\\u9fa5]+").matcher(s4).matches());
// 半角字符, 其中·是半角标点
String s5 = "123abcAZY_?!@#!@·¹¸";//
System.out.println(Pattern.compile("[\\x00-\\xff]+").matcher(s5).matches());

3.空值判断

正常性况下, 空值判断有如下几种情况

  1. null
  2. 空字符串""
  3. 空白字符串" "

java 语言判断方法

System.out.println("".length());
System.out.println(" ".length());
System.out.println(" ".trim().length());
System.out.println("\b\b".trim().length());
System.out.println("\b\t".trim().length());

org.apache.commons.lang3.StringUtils.isBlank("");
org.apache.commons.lang3.StringUtils.isEmpty("");
  • oracle 处理方法, oracle 里 null 等价于 空字符串""
select nvl(null, '') from dual;
select length(' ') from dual;
select * from dcs_h where ' ' = '   ' and rownum < 2;
  • mysql 处理方法, oracle 里 空字符串"" 查询等价于 空白字符串""
select ifnull(null, '');
select length('  ');
select * from dcs_h where '' = '  ' limit 1;
  • sqlserver 处理方法, oracle 里 空字符串"" 查询等价于 空白字符串""
select isnull(null, 1);
select len('  ');
select top 1 * from dcs_h where '' = '   ';

转载于:https://my.oschina.net/u/2948232/blog/831671

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值