6

JS和MySQL常见问题

 1 year ago
source link: https://www.daguanren.cc/post/nodejs-chang-jian-wen-ti.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用like语句搜索时,不能搜索出值为NULL的数据

SELECT *FROM `es_goods` WHERE ( `issale` = 0 ) AND ( `code` LIKE '%%' )

例如使用如上语句搜索时,无法搜索出code为NULL的数据

微信公众号发送模板消息问题

我们批量推送模板消息的时候也遇到这个问题,推动80条消息,分了8次才推完,大部分都会报40001错,但是重新推送又正常了,并不是access_token真的过期了,但是我们好像没有遇到报40001还能收到的问题,所以我们的解决方案是,当报40001的时候,不管access_token有没有过期,都重新获取一次,然后再次推送,如果报40001用户还能收到,那真就无解了,因为无法判断用户到底有没有收到

access_token频繁失效真是个大坑,不止推送模板消息的接口,其他接口也会出现,然而微信并没有给出明确的说法,唯一的解决方案就是刷新access_token再重新调用接口。

大官人我同样用的是一个accesstoken,调了4次模板消息,只有最后1次成功,其他3次不成功。

https://developers.weixin.qq.com/community/develop/doc/0006ec98c64f50118f882e97656400?_at=1563258638370

后端返回buffer,前端提供用户下载

typeof判断类型

console.log(typeof 42);// expected output: "number"console.log(typeof 'blubber');// expected output: "string"console.log(typeof true);// expected output: "boolean"console.log(typeof undeclaredVariable);// expected output: "undefined"coffeescript

将json对象转成键值对

var o = {};var a = 'aaa';o[a] = 'value of aaa';console.log(o);console.log(o[a]);javascript
*.png
var ids = [1,2,3];var names =['小白', '小黑', '小红'];var sexs = ['男','男','女'];var kv = {};for(var i =0; i < ids.length; i++) { let obj = { 'name' : names[i], 'sex': sexs[i] kv[ids[i]] = obj;console.log(kv);matlab
*.png

MySQL拼接group_concat

开发中经常遇到需要多多表group查出的字段进行拼接,类似下图的需求:

*.png

这时就可以使用group_concat实现:

select a.id, name, group_concat(label) as label from 右图表 a,左图表 b where find_in_set(b.id, lid) group by namerouteros

注意点

group_concat默认是1024 字节,ID是27位,加上默认的分隔符“,” 一位,所以一条数据占28字节。换言之,group_concat 的默认配置只支持36条数据。

如果使用的是腾讯云或者阿里云的数据库,则需要在类似此地方更改:

image.png

MySQL中使用SQL语句查询哪个字段的长度不等于16

SELECT * FROM activity WHERE LENGTH(key) != 16 and id > 52

MySQL中对返回结果处理,比如性别返回:0 -> '男', 1 -> '女'

select case WHEN sex = 0 then '男' WHEN sex = 1 then '女' END sexfrom table

JS跳出循环的几种方式(break, return, continue)

break语句会使运行的程序立刻退出包含在最内层的循环或者退出一个switch语句。

for(var i =1; i < 5; i++) { if(i == 3) { break; console.log(i);matlab

输出如下结果:

*.png

continue语句和break语句相似。所不同的是,它不是退出一个循环,而是开始循环的一次新迭代。

for(var i =1; i < 5; i++) { if(i == 3) { continue; console.log(i);matlab

输出如下结果:

*.png

return语句就是用于指定函数返回的值。return语句只能出现在函数体内,出现在代码中的其他任何地方造成语法错误!

输出如下结果:

image.png

大陆地区身份证对应关系:

image.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK