###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.空值判断
正常性况下, 空值判断有如下几种情况
- null
- 空字符串""
- 空白字符串" "
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 '' = ' ';