1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// hireUpi.js
var models = require('../db');
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var $sql = require('../sqlMap');
// 连接数据库
var conn = mysql.createConnection(models.mysql);
conn.connect();
var jsonWrite = function(res, ret) {
if (typeof ret === 'undefined') {
res.send('err')
} else {
//res.json(ret);
res.send('ok')
}
};
// 增加
router.post('/addList', (req, res) => {
var sql = $sql.hire.add
var params = req.body
conn.query(sql, [params.title, params.money, params.degree, params.exp, params.site, params.time, params.addr], function (err, result) {
if (err) {
console.log(err)
}
if (result) {
jsonWrite(res, result)
}
})
})
// 更新
router.post('/updateList', (req, res) => {
var sql = $sql.hire.update
var params = req.body
conn.query(sql, [params.title, params.hire_id], function (err, result) {
if (err) {
console.log(err)
}
if (result) {
jsonWrite(res, result)
}
})
})
//查找
router.get('/searchList', (req, res) => {
var sql = $sql.hire.search
var params = req.query
console.log(params)
conn.query(sql, [params.title], function (err, result) {
if (err) {
console.log(err)
}
if (result) {
console.log(result)
res.send(result)
}
})
})
// 获取所有list
router.get('/getAllList', (req, res) => {
var sql = $sql.hire.getAll
var params = req.query
conn.query(sql, function(err, result) {
if (err) {
console.log(err)
}
if (result) {
console.log(result)
res.send(result)
}
})
})
// 删除
router.post('/delList', (req, res) => {
var sql = $sql.hire.del
var params = req.body
conn.query(sql, [params.hire_id], function (err, result) {
if (err) {
console.log(err)
}
if (result) {
jsonWrite(res, result)
}
})
})
module.exports = router;
|