最近怎么发现
每天出去high,都有新收货呢?
今天汪哥在数字符串长度时,被加菲猫给取笑了
才发现,还能这样?
选中了,右下角居然会显示出来长度 无语了。。。。。。
再看下面这点:
rec_time between
to_date('2020-07-09 00:00:00','yyyy-mm-dd hh24:mi:ss')
and
to_date('2012-07-09 12:00:00','yyyy-mm-dd hh24:mi:ss')
如果有一天你发现 不管你怎么改格式,这个语句都会报语法错误的话
比如下面情况:
@Select({
"<script> select a.rn,a.* from (select rownum rn,z.* from (select t.id,e.data_info camera_no,t.order_code,f.data_info field_no,"
+ "d.data_info detect_type,t.detection_result,t.images_url,t.videos_url,t.remark,"
+ "t.rec_time,t.create_time,t.update_time,t.continued_time,t.read_flag,t.status,t.person_num,t.time_stamp,t.time_stamp_date,change_id,send_status,order_id "
+ " from ${tableName} t left join dic_data d on t.detect_type=d.data_no "
+ " left join dic_data e on t.camera_no=e.data_no \r\n" +
" left join dic_data f on t.field_no=f.data_no where " +
" and t.status='1' and d.type='3' "
+ " and d.status = #{status} and e.type='2' and e.status = #{status} and f.type='1' and f.status = #{status}"
+"<when test = 'cameraNo!=null'> and t.camera_no = #{cameraNo} </when>"
+"<when test = 'fieldNo!=null'> and t.field_no = #{fieldNo} </when>"
+"<when test = 'detectType!=null'> and t.detect_type = #{detectType} </when>"
+"<when test = 'recTime1!=null'> and t.rec_time between to_date('2012-05-01 00:00:00','yyyy-mm-dd hh24:mi:ss') "
+"and to_date('2012-05-31 00:00:00','yyyy-mm-dd hh24:mi:ss') </when>"
请用以下代码果断替掉她:
t.rec_time > to_date(#{
recTime1},'yyyy-MM-dd Hh24:mi:ss')
and
t.rec_time < to_date(#{
recTime2},'yyyy-MM-dd Hh24:mi:ss')
再看第三点:
字符串的isEmpty()方法,源码如下:
public boolean isEmpty() {
return this.value.length == 0;
}
取得是字符串的长度等于0来比较,如果Object,不能用,会报空指针
import org.springframework.util.StringUtils;
StringUtils工具类,源码如下:
public static boolean isEmpty(@Nullable Object str) {
return str == null || "".equals(str);
}
除了验证字符串非空,也是可以校验Object非空的
再看第四点:
今天在用websocket进行长链接数据监测时,发现,“sessionID”原来不是顺序递增的,而是下面这样的:
出于好奇,查看了他的算法源码,如下:
internal static class SessionId
{
internal const int NUM_CHARS_IN_ENCODING = 32;
internal const int ENCODING_BITS_PER_CHAR = 5;
internal const int ID_LENGTH_BITS = 120;
internal const int ID_LENGTH_BYTES = 15;
internal const int ID_LENGTH_CHARS = 24;
private static char[] s_encoding;
private static bool[] s_legalchars;
internal static bool IsLegit(string s)
{
if (s == null || s.Length != 24)
{
return false;
}
bool result;
try
{
int num = 24;
while (--num >= 0)
{
char c = s[num];
if (!SessionId.s_legalchars[(int)c])
{
result = false;
return result;
}
}
result = true;
}
catch (IndexOutOfRangeException)
{
result = false;
}
return result;
}
internal static string Create(ref RandomNumberGenerator randgen)
{
if (randgen == null)
{
randgen = new RNGCryptoServiceProvider();
}
byte[] array = new byte[15];
randgen.GetBytes(array);
return SessionId.Encode(array);
}
static SessionId()
{
SessionId.s_encoding = new char[]
{
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'0',
'1',
'2',
'3',
'4',
'5'
};
SessionId.s_legalchars = new bool[128];
for (int i = SessionId.s_encoding.Length - 1; i >= 0; i--)
{
char c = SessionId.s_encoding[i];
SessionId.s_legalchars[(int)c] = true;
}
}
private static string Encode(byte[] buffer)
{
char[] array = new char[24];
int num = 0;
for (int i = 0; i < 15; i += 5)
{
int num2 = (int)buffer[i] | (int)buffer[i + 1] << 8 | (int)buffer[i + 2] << 16 | (int)buffer[i + 3] << 24;
int num3 = num2 & 31;
array[num++] = SessionId.s_encoding[num3];
num3 = (num2 >> 5 & 31);
array[num++] = SessionId.s_encoding[num3];
num3 = (num2 >> 10 & 31);
array[num++] = SessionId.s_encoding[num3];
num3 = (num2 >> 15 & 31);
array[num++] = SessionId.s_encoding[num3];
num3 = (num2 >> 20 & 31);
array[num++] = SessionId.s_encoding[num3];
num3 = (num2 >> 25 & 31);
array[num++] = SessionId.s_encoding[num3];
num2 = ((num2 >> 30 & 3) | (int)buffer[i + 4] << 2);
num3 = (num2 & 31);
array[num++] = SessionId.s_encoding[num3];
num3 = (num2 >> 5 & 31);
array[num++] = SessionId.s_encoding[num3];
}
return new string(array);
}
}
本汪查了点资料,作为拓展了解:
sessionid是一个会话的key,浏览器第一次访问服务器会在服务器端生成一个session,有一个sessionid和它对应。tomcat生成的sessionid叫做jsessionid。
虽然不是有序的,但不同会话,sessionID是不会相同的,这个算法,可以当作生成不重复随机数算法来借鉴应用哦