集合类 | Key | Value | Super | 说明 ---|------|------|-----|------|--- Hashtable |不允许为 null | 不允许为 null | Dictionary | 线程安全 ConcurrentHashMap| 不允许为 null| 不允许为 null |AbstractMap | 锁分段技术(JDK8:CAS) TreeMap| 不允许为 null |允许为 null |AbstractMap| 线程不安全 HashMap |允许为 null| 允许为 null |AbstractMap | 线程不安全
ConcurrentHashMap 存储 null 值时会抛出 NPE 异常.
private static final ThreadLocal<DateFormat> df = new ThreadLocal<DateFormat>() {
@ Override
protected DateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd");
}
};
jdk8 可以使用DateTimeFormatter代替simpleDateFormat
if (condition) {
...
return obj;
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(Abc.class);
在linux服务器上通过变更/etc/sysctl.conf修改缺省值
net.ipv4.tcp_fin_timeout = 30
在Dao层,无法用细粒度异常进行catch,所以使用catch(Exception e) 方式,并throw new DAOException(e) 不进行打印。
在manager/service层进行捕获,并打印到日志中,service层将日志输出到磁盘,web层跳转到友好界面。
select if(isnull(sum(g)),0,sum(g)) from table;
select length("轻松工作");返回12
select character_length("轻松工作"); 返回4
存储表情用utfmb4来进行存储,注意它与utf-8的区别。
8.不建议使用truncate
count(distinct left(列名,索引长度))/count(*)
索引 a_b_c where a = ? and b = ? order by c
索引中有范围查找时,索引的有序性无法利用,where a > 10 order by b; 索引 a_b无法发生。
{var} 会显示在页面上。