比较对象为空还是null
object.isEmpty() //是判断对象是否是空字符串 如果object为null会报出空指针异常
**比较对象是否为空还是用 == null**
重启nginx
nginx -s reload
oracle数据库时间类型取出
直接取出为Timestamp类型 无法直接转换为String
将取出类型转换为String
String strn = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time);
查询时候就做to_char处理 ( 注意取别名 )
to_char('time','yyyy-MM-dd HH24:mi:ss') time
String保存为data的时候用to_data
TO_DATE('time', 'YYYY-MM-DD HH24:MI:SS')
oracle数据库中的字符串拼接用 ||
update ATMSURGERY.ATM_CUSTOM_DATA data set FORM_ID=(select ID
from ATMSURGERY.ATM_FORM_TEMP t
where t.form_content like '%'||data.ITEM_NAME||'%' );
|| 和&& 区别
|| 遇 true 则 true
&& 遇 false 则 false
字符串时间转时间戳
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startTimestamp = sdf.parse(Time).getTime();
mysql中 = null 和 is null 有什么不同
根据字段设置来
如果字段设置为可以置空 当没有插入值时数据库系统会自动插入一个“NULL”值
如果字段定义为 not null,但是却赋值了一个 null,那么数据库系统会按照该字段类型选择一个默认的值放进去,
如 char 就是用空字符串。
但注意,空字符串其实已经是一个确定的值了,就是一个长度为 0 的字符串!
当 = null 或者 != null 的比对时 会永远返回false
只能用 is null 或者 not null 来做空值比较
RedisTemplate 添加数据失败报空指针异常
在RedisUtil 中引入RedisTemplate的时候没有使用@Resource而是用的@Autowired 导致RedisTemplate没有正确的引入
将
@Autowired
private RedisTemplate<String,String> redisTemplate;
换成
@Resource
private RedisTemplate<String,String> redisTemplate;
order by 按照指定数组排序
select * from table order by substring_index((1,2,3,4,5),id,1)
按照 1,2,3,4,5 的顺序升序排序
select * from table order by id desc //降序排序
FIND_IN_SET()函数
(FIND_IN_SET(269, approve_user_id)
查询approve_user_id中是否存在269这个数
approve_user_id的类型是1,2,3,4,5,6,269
GROUP_CONCAT()函数
GROUP_CONCAT(instance_id)
对查询出来的instance_id进行合并 分隔符为,
123,456,789,10
CONCAT(‘%’,#{keyword},‘%’) mybatis sql字符串拼接
CONCAT('%',#{keyword},'%')
union all 合并查询结果
select status, start_date, end_date
from (select status, start_date, end_date from room where status = 1 order by start_date) a
union all
select status, start_date, end_date
from (select status, start_date, end_date from room where status = 0 order by start_date) b
union all
select status, start_date, end_date
from (select status, start_date, end_date from room where room.status = 2 order by end_date desc) c
先排序再合并 union all 优先级比 order by 高
CONCAT(FROM_UNIXTIME(start_date/1000,‘%Y-%m-%d %H:%i:%s’),‘至’,FROM_UNIXTIME(end_date/1000,‘%Y-%m-%d %H:%i:%s’)), 时间转换和列合并
select CONCAT(FROM_UNIXTIME(start_date/1000,'%Y-%m-%d %H:%i:%s'),'至',FROM_UNIXTIME(end_date/1000,'%Y-%m-%d %H:%i:%s')), form room
结果
2021-05-01 00:01:40至2021-05-31 23:59:59
时间戳转换成日期FROM_UNIXTIME():
FROM_UNIXTIME(1429063399,'%Y-%m-%d %H:%i:%s')
如果不需要时分秒,'%Y-%m-%d'就好
上面例子中使用的是10位时间戳,若是13位时间戳需要/1000,如下:
FROM_UNIXTIME(1429063399123/1000,'%Y-%m-%d %H:%i:%s')
日期转换为时间戳UNIX_TIMESTAMP():
UNIX_TIMESTAMP('2015-04-15')
%Y年、%m月、%d日、%H时、%i分、%s秒最为常用
if修改sql结果
select if(status=0,'未开始',
if ( status=1,'已开始',
if( status=2,'已结束','异常直播')))
from room
# 用if对字段的值进行指定的修改
if(字段=值,修改成的值,
if(字段=值,修改成的值,都不满足修改的值))
ON DUPLICATE KEY UPDATE 添加失败则修改
INSERT INTO user_extend_info (id_card, birthday, `user`, last_modify_time, create_date)
VALUES (#{idCard}, #{birthday}, #{userId}, (SELECT unix_timestamp(now()) * 1000),
(SELECT unix_timestamp(now()) * 1000))
ON DUPLICATE KEY UPDATE id_card=IFNULL(#{idCard}, VALUES(id_card)),
birthday=IFNULL(#{birthday}, VALUES(birthday)),
last_modify_time = (SELECT unix_timestamp(now()) * 1000)
NOT IN 排除
select * from wf_define_record where id NOT IN (1,2,3,4)
排除id等于1,2,3,4的其他数据
concat_wa 多个字段合并成一个字段
select CONCAT_WS(',',d.id,dd.id,ddd.id,dddd.id,ddddd.id,dddddd.id,ddddddd.id) ids
from system_user u
left join department d on d.id=u.department
left join department dd on dd.id=d.parent
left join department ddd on ddd.id=dd.parent
left join department dddd on dddd.id=ddd.parent
left join department ddddd on ddddd.id=dddd.parent
left join department dddddd on dddddd.id=ddddd.parent
left join department ddddddd on ddddddd.id=dddddd.parent
where u.id =125;
结果 多个字段通过','合并成
redisTemplate操作方法
//1、通过redisTemplate设置值
redisTemplate.boundHashOps("HashKey").put("SmallKey", "HashVaue");
//绑定HashKey操作
BoundHashOperations redis = redisTemplate.boundHashOps("ModuleRecord");
//1、通过redisTemplate设置值
redis.put("SmallKey", "HashVaue");
//2、通过BoundValueOperations获取值
String value2 = (String) redis.get("SmallKey");
//添加一个临时key 持续5秒 作用: 五秒内 多次访问刷新模块都只记录一次
redisTemplate.opsForValue().set("snap:" + HashKey, "3", 5, TimeUnit.SECONDS);
PageHelper中new PageInfo(list) 只能是list不能是arraylist
PageHelper.startPage(currentPage, pageSize);
ArrayList applicationRecord = approvalRecordMapper.getProcessRecordAccordingToId(user, apply_time, process_status, record_id, fuzzySearch);
PageInfo pageInfo = new PageInfo(applicationRecord);
只能是arraylist 不能死JSONArray模式
对中文进行排序
/**
* 对人名进行排序按照A-Z的顺序
*
* @param name 需要排序的人名 逗号分割 (张三,李四,王五,赵六,陈真---排序后-->陈真,李四,王五,赵六,张三)
* @return 排序后的名称
*/
@Override
public String sortByName(String name) {
if (name != null) {
String[] split = name.split(",");
List<String> newusernae = new ArrayList<>();
Collections.addAll(newusernae, split);
newusernae = newusernae.stream().sorted((oldname, newname) -> {
Collator instance = Collator.getInstance(Locale.CHINA);
return instance.compare(oldname, newname);
}).collect(Collectors.toList());
String newname = newusernae.toString().substring(1, newusernae.toString().length() - 1);
return newname;
}
return null;
}
添加数据返回添加id
添加数据后返回Id
<insert id="" parameterType="" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
useGeneratedKeys:必须设置为true,否则无法获取到主键id。
keyProperty:设置为POJO对象的主键id属性名称。
keyColumn:设置为数据库记录的主键id字段名称。
对多个数据多个值进行更新
UPDATE categories
SET display_order = CASE id
WHEN 1 THEN 3
WHEN 2 THEN 4
WHEN 3 THEN 5
END,
title = CASE id
WHEN 1 THEN 'New Title 1'
WHEN 2 THEN 'New Title 2'
WHEN 3 THEN 'New Title 3'
END
WHERE id IN (1,2,3)
这句sql的意思是,更新display_order 字段,如果id=1 则display_order 的值为3,如果id=2 则 display_order 的值为4,如果id=3 则 display_order 的值为5。
即是将条件语句写在了一起。
这里的where部分不影响代码的执行,但是会提高sql执行的效率。确保sql语句仅执行需要修改的行数,这里只有3条数据进行更新,而where子句确保只有3行数据执行。
insert into online_school.school_user_study_plan (user_id, obtain_plan_id, live_id, live_time, question_id, fraction,
end_time, is_end)
values (31180, 176, 18920, 3000, null, null, 1632360134495, 0)
ON DUPLICATE KEY UPDATE is_end = IF( 10000* 0.9 <= (select live_time
from ((select ((school_user_study_plan.live_time + 3000) ) as live_time
from online_school.school_user_study_plan
where user_id = 31180
and obtain_plan_id = 176
and live_id = 18920)) a), 1, 0)
if也可以做条件比较
计数 COUNT()
select COUNT(id)
from online_school.school_user_study_plan susp2
where susp2.obtain_plan_id = susp.obtain_plan_id
计算一个字段逗号分割有多少
select plan_type,
by_live,
by_room,
by_question,
if(plan_type = 1, (select CHAR_LENGTH(by_live) - CHAR_LENGTH(REPLACE(by_live, ',', '')) + 1
from online_school.obtain_credentials_full_plan
where id = plan.id),
if(plan_type = 2, (select CHAR_LENGTH(by_question) - CHAR_LENGTH(REPLACE(by_question, ',', '')) + 1
from online_school.obtain_credentials_full_plan
where id = plan.id),
if(plan_type = 3, (select CHAR_LENGTH(by_question) - CHAR_LENGTH(REPLACE(by_question, ',', '')) + 1
from online_school.obtain_credentials_full_plan
where id = plan.id),
if(plan_type = 4, (select CHAR_LENGTH(by_question) - CHAR_LENGTH(REPLACE(by_question, ',', '')) + 1
from online_school.obtain_credentials_full_plan
where id = plan.id),
if(plan_type = 5, (select CHAR_LENGTH(by_room) - CHAR_LENGTH(REPLACE(by_room, ',', '')) + 1
from online_school.obtain_credentials_full_plan
where id = plan.id), null))))) total
from online_school.obtain_credentials_full_plan plan
where obtain_id = 38;
sql当中的 当前时间
select unix_timestamp(current_timestamp()) * 1000
sql中获取当前时间 *1000 成为时间戳形式 毫秒值
返回实体类不返回null字段
在类上或者属性上面添加
@JsonInclude(JsonInclude.Include.NON_EMPTY)
子序列和子串的区别
子串:原序列中必须连续的一段
子序列:原序列中可以不连续的一段
注意:无论是子串和子序列,元素的顺序都是原序列中的顺序
Math.max()方法 返回最大值
public static int max(int a, int b) {
return (a >= b) ? a : b;
}
/ 返回两个值中的最大值
map.containsKey()判断是否有这个key
if(map.containsKey("name")){
value=map.get("name").toString();
System.out.println("找到了name的值:"+value);
}
// map中的containsKey(key)方法是判断该key在map中是否有key存在。如果存在则返回true。如果不存在则返回false。
tail -n 20 filename
说明:显示filename最后20行
Cast(字段名 as 转换的类型 )
sql转换类型
select topicReal.id as topicRealId,
topicReal.name as topicRealName,
topicReal.start_time as startTime,
topicReal.end_time as endTime,
c1.name as intentionName,
c1.id as intentionId,
c2.name as subjectName,
c2.id as subjectId,
c3.name as sectionName,
c3.id as sectionId,
season.name as seasonName,
season.id as seasonId,
Cast(CONCAT((select COUNT(user_id)
from online_school.school_topic_real_simulation_user_record re
where re.topic_real = topicReal.id
and re.submit_state = 1),'/',(select COUNT(user_id)
from online_school.school_topic_real_simulation_user_record re
where re.topic_real = topicReal.id)) as CHAR )
as examNumber,
(select COUNT(user_id)
from online_school.school_topic_real_simulation_user_record re
where re.topic_real = topicReal.id
and re.submit_state = 1
and re.synchronization = 0) as toBeRated
from online_school.school_topic_real topicReal
left join online_school.school_category c3 on c3.id = topicReal.section
left join online_school.school_category c2 on c2.id = c3.parent
left join online_school.school_category c1 on c1.id = c2.parent
left join online_school.school_exam_season season on season.id = topicReal.exam_season
left join online_school.school_topic_real_simulation_user_record record on record.topic_real = topicReal.id
where topicReal.deleted_state = 0;
CAST数据类型转化
使用方法:
Cast(字段名 as 转换的类型 )
日志查询最后100行
tail -f -n 100 日志文件名
{"return_code":"SUCCESS","mch_appid":"wx800bda100821d048","mchid":"1618863581","device_info":"WEB","nonce_str":"9PXRZIWLXIBTOY0EJPEZ31NA6A58WWA1","result_code":"SUCCESS","partner_trade_no":"42168636614916779","payment_no":"10101391761222306106782944304968","payment_time":"2023-06-10 11:02:29","request_tag":"<TreeMap><amount>500</amount><apikey>KR77U9732D988OF0N1795I964N671WGO</apikey><check_name>NO_CHECK</check_name><desc>重庆</desc><device_info>WEB</device_info><mch_appid>wx800bda100821d048</mch_appid><mchid>1618863581</mchid><nonce_str>9PXRZIWLXIBTOY0EJPEZ31NA6A58WWA1</nonce_str><openid>o3uNi60XEoY9B8x56b6penSiZSu0</openid><partner_trade_no>42168636614916779</partner_trade_no><sign>9613D26AEDF1E29830CB82593927E5F3</sign><spbill_create_ip>113.250.224.52</spbill_create_ip></TreeMap>","return_tag":"<xml>\n<return_code>SUCCESS</return_code>\n<return_msg></return_msg>\n<mch_appid>wx800bda100821d048</mch_appid>\n<mchid>1618863581</mchid>\n<device_info>WEB</device_info>\n<nonce_str>9PXRZIWLXIBTOY0EJPEZ31NA6A58WWA1</nonce_str>\n<result_code>SUCCESS</result_code>\n<partner_trade_no>42168636614916779</partner_trade_no>\n<payment_no>10101391761222306106782944304968</payment_no>\n<payment_time>2023-06-10 11:02:29</payment_time>\n</xml>"}
n_code>SUCCESS</return_code>\n<return_msg></return_msg>\n<mch_appid>wx800bda100821d048</mch_appid>\n1618863581\n<device_info>WEB</device_info>\n<nonce_str>9PXRZIWLXIBTOY0EJPEZ31NA6A58WWA1</nonce_str>\n<result_code>SUCCESS</result_code>\n<partner_trade_no>42168636614916779</partner_trade_no>\n<payment_no>10101391761222306106782944304968</payment_no>\n<payment_time>2023-06-10 11:02:29</payment_time>\n"}