Skip to content

Commit 009ff53

Browse files
committed
增加web笔记
1 parent 7b9cdb7 commit 009ff53

13 files changed

+473
-4
lines changed

.README.md.swp

-20 KB
Binary file not shown.

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,38 @@ Android-Note同时是博主的一个学习笔记,之前博主尝试着维护
187187
- [ReactNative调试心得](/ReactNative相关/ReactNative调试心得.md)
188188
- [React/React Native 的ES5 ES6写法对照表](https://github.com/linsir6/ReactNativeNote/blob/master/ReactNative%E7%9B%B8%E5%85%B3/React%20Native%20%E7%9A%84ES5%20ES6%E5%86%99%E6%B3%95%E5%AF%B9%E7%85%A7%E8%A1%A8.md)
189189

190-
190+
----
191191

192192
## Script-Note
193193

194194
### 基础
195195

196196
- [简单的Shell脚本](/ScriptNote/简单的Shell脚本.md)
197197
- [一篇文章学懂Shell脚本](/ScriptNote/一篇文章学懂Shell脚本.md)
198+
- [GitHub基础操作](/ScriptNote/GitHub基础操作.md)
199+
- [封装一些GitHub常用命令](/ScriptNote/封装一些GitHub常用命令.md)
200+
198201

202+
----
199203

204+
## Web-Note
200205

201-
### GitHub相关
206+
### NodeJS相关
202207

208+
- [淘宝cnpm](/WebNote/NodeJS相关/淘宝cnpm.md)
209+
- [koa框架对post内容读取并解析](/WebNote/NodeJS相关/koa框架对post内容读取并解析.md)
210+
- [nodejs查询数据库后将值返回前端](/WebNote/NodeJS相关/nodejs查询数据库后将值返回前端.md)
211+
- [nodejs项目在云服务器的部署](/WebNote/NodeJS相关/nodejs项目在云服务器的部署.md)
203212

213+
----
204214

205-
- [GitHub基础操作](/ScriptNote/GitHub基础操作.md)
206-
- [封装一些GitHub常用命令](/ScriptNote/封装一些GitHub常用命令.md)
215+
### MySQL相关
216+
217+
- [linux下安装MySQL](/WebNote/MySQL相关/云服务器linux下安装MySQL.md)
218+
- [MySQL基础操作](/WebNote/MySQL相关/mysql基础操作.md)
219+
- [MySQL导出数据库、表](/WebNote/MySQL相关/Mysql导出数据库、表(有无数据).md)
220+
- [Error-ER_TRUNCATED_WRONG_VALUE_FOR_FIELD](/WebNote/MySQL相关/Error--ER_TRUNCATED_WRONG_VALUE_FOR_FIELD.md)
221+
- [ERROR-1045-(28000)--Access-denied-for-user-'debian-sys-maint'@'localhost](/WebNote/MySQL相关/ERROR-1045-(28000)--Access-denied-for-user-'debian-sys-maint'@'localho.md)
207222

208223

209224

WebNote/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# WebNote
2+
3+
4+
[![Travis](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://github.com/linsir6) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [![GitHub (pre-)release](https://img.shields.io/badge/release-v1.0.0-ff69b4.svg)](https://github.com/linsir6/Android-Notes/releases) [![User](https://img.shields.io/badge/user-linsir-yellow.svg)](https://github.com/linsir6)
5+
6+
记录一些在学习Js,NodeJs,数据库相关方面知识的资料,欢迎fork,star~
7+
8+
9+
10+
## NodeJS相关
11+
12+
- [淘宝cnpm](/WebNote/NodeJS相关/淘宝cnpm.md)
13+
- [koa框架对post内容读取并解析](/WebNote/NodeJS相关/koa框架对post内容读取并解析.md)
14+
- [nodejs查询数据库后将值返回前端](/WebNote/NodeJS相关/nodejs查询数据库后将值返回前端.md)
15+
- [nodejs项目在云服务器的部署](/WebNote/NodeJS相关/nodejs项目在云服务器的部署.md)
16+
17+
----
18+
19+
## MySQL相关
20+
21+
- [linux下安装MySQL](/WebNote/MySQL相关/云服务器linux下安装MySQL.md)
22+
- [MySQL基础操作](/WebNote/MySQL相关/mysql基础操作.md)
23+
- [MySQL导出数据库、表](/WebNote/MySQL相关/Mysql导出数据库、表(有无数据).md)
24+
- [Error-ER_TRUNCATED_WRONG_VALUE_FOR_FIELD](/WebNote/MySQL相关/Error--ER_TRUNCATED_WRONG_VALUE_FOR_FIELD.md)
25+
- [ERROR-1045-(28000)--Access-denied-for-user-'debian-sys-maint'@'localhost](/WebNote/MySQL相关/ERROR-1045-(28000)--Access-denied-for-user-'debian-sys-maint'@'localho.md)
26+
27+
28+
29+
----
30+
31+
# Getting Help
32+
33+
To report a specific problem or feature request, open a new issue on Github. For questions, suggestions, or anything else, email linsir678@gmail.com.
34+
35+
36+
37+
# Author
38+
39+
关玮琳linSir - @[linsir6](https://github.com/linsir6) on GitHub, @[linsir.top](http://linsir.top)
40+
41+
# License
42+
43+
Copyright 2017 linsir
44+
45+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
46+
47+
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
48+
49+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
50+
51+
52+
53+
# PS
54+
**已经看到这里啦,不妨给个star~**
55+
56+
![](/WebNote/img/background.jpg)
57+
58+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
> 原本linux(Ubuntu)上面安装mysql是非常简单的事情,但是我今天真是b了狗了,装个mysql,运行各种失败,希望大家以后遇到这个问题别这么难过啦。
2+
3+
4+
````
5+
ERROR 1045 (28000): Access denied for user 'ubuntu'@'localhost' (using password: YES)
6+
ERROR 1045 (28000): Access denied for user 'ubuntu'@'localhost' (using password: NO)
7+
````
8+
9+
10+
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/2585384-3889166b952adcb3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
11+
12+
13+
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/2585384-7adc01e923ec74f7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
14+
15+
其实这里面提供了,我们可以登录的账号密码,只需要暂时用这个登录,然后再授权一个新用户就行。
16+
17+
以上便是这个问题的解决方案啦。
18+
19+
20+
21+
22+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
![错误截图](http://upload-images.jianshu.io/upload_images/2585384-23615f16a18323d9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2+
3+
> 形如上面的错误,发生在向mysql数据库中插入中文的时候,编码格式遇到了问题,上Stack Overflow看了一下,应该是编码格式的问题。
4+
5+
解决方法是改变数据库的编码格式:
6+
7+
```
8+
mysql> alter database test character set gbk;
9+
```
10+
这样我们数据库的编码格式就发生了改变,就可以插入中文了。但是原有已经有了的表还是不可以,因为已经有的表的编码格式还是默认的,所以需要将原有的表也改变一下:
11+
12+
```
13+
mysql> alter table test character set gbk;
14+
```
15+
16+
好了,到这问题就解决啦~~
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
> 在命令行下导出数据库、表(有无数据)具体用法如下:
2+
3+
```
4+
mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名;
5+
```
6+
7+
8+
![效果图](http://upload-images.jianshu.io/upload_images/2585384-8acc14df2492d804.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
9+
10+
11+
---
12+
13+
导出整个数据库结构和数据:
14+
```
15+
mysqldump -h localhost -uroot -p123456 database > dump.sql
16+
```
17+
----
18+
19+
导出单个数据表结构和数据:
20+
21+
```
22+
mysqldump -h localhost -uroot -p123456 database table > dump.sql
23+
```
24+
---
25+
26+
27+
28+
导出整个数据库结构(不包含数据):
29+
30+
```
31+
32+
mysqldump -h localhost -uroot -p123456 -d database > dump.sql
33+
34+
```
35+
----
36+
37+
导出单个数据表结构(不包含数据):
38+
39+
```
40+
mysqldump -h localhost -uroot -p123456 -d database table > dump.sql
41+
42+
```
43+
44+
----
45+
如果提示权限异常,请注意,是否在当前目录下具有写文件的权利,如果没有可以切换到别的目录下面,再执行这个操作。
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
创建数据库:
2+
````
3+
create database db_biology;
4+
````
5+
操作该数据库:
6+
````
7+
use db_biology;
8+
````
9+
导入表到制定数据库
10+
````
11+
mysql -u用户名 -p 数据库名 < 数据库名.sql
12+
#mysql -uroot -p abc < abc.sql
13+
````
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
1.linux下安装mysql:
2+
````
3+
sudo apt-get update
4+
sudo apt-get install mysql-client-core-5.6
5+
sudo apt-get install mysql-client-5.6
6+
sudo apt-get install mysql-server-5.6
7+
````
8+
9+
以上便是安装MySQL的全过程了。
10+
11+
----
12+
2.查看是否运行:
13+
````
14+
ps -ef | grep mysql
15+
````
16+
----
17+
3.MySQL的停止:
18+
````
19+
sudo service mysql stop
20+
````
21+
----
22+
4.MySQL的开启:
23+
````
24+
sudo service mysql start
25+
````
26+
----
27+
5.MySQL的重启:
28+
````
29+
service mysql restart
30+
````
31+
----
32+
6.MySQL的登录
33+
````
34+
mysql -u root -p #这里面的root是用户名
35+
````
36+
37+
38+
39+
40+
41+
42+
43+
44+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
> 最近在写一个小项目,需要涉及到前端向后端发送一个jsonArray,然后我们后端采用的是node的koa框架,所以需要用http发送,然后这个http包含着一个content即可
2+
3+
````
4+
移动端的发送代码
5+
6+
JSONArray jsonArray = new JSONArray();
7+
for (int i = 0; i < 5; i++) {
8+
JSONObject object = new JSONObject();
9+
try {
10+
object.put("user_id", "11111111111");
11+
object.put("user_name", "2222222222");
12+
object.put("user_phone", "33333333333");
13+
object.put("user_address", "444444444444");
14+
object.put("product_id", "5555555555");
15+
object.put("product_name", "666666666666");
16+
object.put("product_price", "77777777777");
17+
object.put("product_count", "88888888888");
18+
} catch (JSONException e) {
19+
Log.i("lin", "---lin's log---> 进入 catch");
20+
e.printStackTrace();
21+
}
22+
jsonArray.put(object);
23+
}
24+
String content = jsonArray.toString();
25+
OkHttpUtils
26+
.postString()
27+
.url("http://172.20.10.4:3008/testjson")
28+
.content(content)
29+
.build()
30+
.execute(new StringCallback() {
31+
@Override public void onError(Request request, Exception e) {
32+
Toast.makeText(TestActivity.this, "error", Toast.LENGTH_SHORT).show();
33+
Log.i("lin", "---lin's log---> error " + e.toString());
34+
}
35+
36+
@Override public void onResponse(String response) {
37+
Toast.makeText(TestActivity.this, "onResponse", Toast.LENGTH_SHORT).show();
38+
Log.i("lin", "---lin's log---> response " + response);
39+
}
40+
});
41+
42+
43+
````
44+
45+
46+
后端接收的代码:
47+
48+
````
49+
var koa = require('koa');
50+
var controller = require('koa-route');
51+
var parse = require('co-body');
52+
var app = koa();
53+
54+
app.use(controller.post('/testjson', function*() {
55+
console.log("接收到请求~");
56+
var item = yield parse(this);
57+
var jsonList = eval(item);
58+
for (var i = 0; i < jsonList.length; i++) {
59+
console.log(jsonList[i].user_id);
60+
console.log(jsonList[i].user_name);
61+
}
62+
63+
this.set('Cache-Control', 'no-cache');
64+
this.body = "100";
65+
}));
66+
67+
68+
69+
70+
````
71+
72+
73+
![效果图](http://upload-images.jianshu.io/upload_images/2585384-de9c26d5e62ee471.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
74+
75+
以上便可以实现,前端向后端发送jsonArray并将其解析的过程啦~
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
> nodejs最大的优势也是大家用着最为难以理解的一点,就是它的异步功能,它几乎所有的io操作都是异步的,这也就导致很多人不理解也用不习惯。
2+
3+
前几天在项目中遇到这样一个问题,就是前端触发某个请求,想要查询数据库并且返回这个值,但是无论如何都返回不回来,因为没等到查询完毕,就过早的将空数据返回回来了,这个困扰了我许久,当时想到一些替代的方法,都是不治本的方法,今天打算用promise重新解决这个问题。
4+
5+
promise的作用是让原本异步执行的代码变成类似同步执行,就是在执行完之后,会将结果返回回来。当然,我目前也只对promise只有一个浅显的理解,在之后也会深入学习的,下面说一下这个问题是怎么解决的。
6+
7+
````
8+
app.use(controller.get('/aaa', function*() {
9+
this.set('Cache-Control', 'no-cache');
10+
var data = yield service.bbb();
11+
this.body = data;
12+
}));
13+
````
14+
15+
我们可以使用koa框架中的yield,promise可以作为它的返回参数。
16+
17+
18+
````
19+
exports.bbb = function () {
20+
var promise = new Promise(function (resolve, reject) {
21+
var mysql = require('mysql');
22+
var connection = mysql.createConnection({
23+
host: '127.0.0.1',
24+
user: 'root',
25+
password: 'root',
26+
port: '3306',
27+
database: 'db_biology'
28+
});
29+
connection.connect();
30+
connection.query(
31+
"SELECT * FROM Sheet1",
32+
function selectCb(err, results) {
33+
if (results) {
34+
console.log(results);
35+
//resolve(results);
36+
resolve(results);
37+
}
38+
if (err) {
39+
console.log(err);
40+
}
41+
connection.end();
42+
}
43+
);
44+
});
45+
promise.then(function (value) {
46+
console.log(value);
47+
return value;
48+
// success
49+
}, function (value) {
50+
// failure
51+
});
52+
return promise;
53+
};
54+
````
55+
56+
只需要利用promise就可以实现我们以前直接return的结果了,这样就优雅的将异步代码变成了同步的了~
57+
58+
59+
60+
61+
62+
63+

0 commit comments

Comments
 (0)