当前位置: 首页 > news >正文

做网站销售大数据营销精准营销

做网站销售,大数据营销精准营销,邢台搜,推荐一个好点的网站1.在自己的项目JS文件夹中建文件:config.js、mssql.js和server.js以及api文件夹下的user.js 2.在config.js中封装数据库信息 let app {user: sa, //这里写你的数据库的用户名password: ,//这里写数据库的密码server: localhost,database: medicineSystem, // 数据…

1.在自己的项目JS文件夹中建文件:config.js、mssql.js和server.js以及api文件夹下的user.js

2.在config.js中封装数据库信息

let app = {user: 'sa', //这里写你的数据库的用户名password: '',//这里写数据库的密码server: 'localhost',database: 'medicineSystem', // 数据库名字port: 1433, //端口号,默认1433options: {encrypt: false,  //加密,设置为true时会连接失败 Failed to connect to localhost:1433 - self signed certificateenableArithAbort: false},pool: {min: 0,max: 10,idleTimeoutMillis: 3000}
}module.exports = app

3.在mssql.js中对sql语句的二次封装

//mssql.js
/***sqlserver Model**/
const mssql = require("mssql");
const conf = require("./config.js");const pool = new mssql.ConnectionPool(conf)
const poolConnect = pool.connect()pool.on('error', err => {console.log('error: ', err)
})
/*** 自由查询* @param sql sql语句,例如: 'select * from news where id = @id'* @param params 参数,用来解释sql中的@*,例如: { id: id }* @param callBack 回调函数*/
let querySql = async function (sql, params, callBack) {try {let ps = new mssql.PreparedStatement(await poolConnect);if (params != "") {for (let index in params) {if (typeof params[index] == "number") {ps.input(index, mssql.Int);} else if (typeof params[index] == "string") {ps.input(index, mssql.NVarChar);}}}ps.prepare(sql, function (err) {if (err)console.log(err);ps.execute(params, function (err, recordset) {callBack(err, recordset);ps.unprepare(function (err) {if (err)console.log(err);});});});} catch (e) {console.log(e)}
};/*** 按条件和需求查询指定表* @param tableName 数据库表名,例:'news'* @param topNumber 只查询前几个数据,可为空,为空表示查询所有* @param whereSql 条件语句,例:'where id = @id'* @param params 参数,用来解释sql中的@*,例如: { id: id }* @param orderSql 排序语句,例:'order by created_date'* @param callBack 回调函数*/
let select = async function (tableName, topNumber, whereSql, params, orderSql, callBack) {try {let ps = new mssql.PreparedStatement(await poolConnect);let sql = "select * from " + tableName + " ";if (topNumber != "") {sql = "select top(" + topNumber + ") * from " + tableName + " ";}sql += whereSql + " ";if (params != "") {for (let index in params) {if (typeof params[index] == "number") {ps.input(index, mssql.Int);} else if (typeof params[index] == "string") {ps.input(index, mssql.NVarChar);}}}sql += orderSql;console.log(sql);ps.prepare(sql, function (err) {if (err)console.log(err);ps.execute(params, function (err, recordset) {callBack(err, recordset);ps.unprepare(function (err) {if (err)console.log(err);});});});} catch (e) {console.log(e)}
};/*** 查询指定表的所有数据* @param tableName 数据库表名* @param callBack 回调函数*/
let selectAll = async function (tableName, callBack) {try {let ps = new mssql.PreparedStatement(await poolConnect);let sql = "select * from " + tableName + " ";ps.prepare(sql, function (err) {if (err)console.log(err);ps.execute("", function (err, recordset) {callBack(err, recordset);ps.unprepare(function (err) {if (err)console.log(err);});});});} catch (e) {console.log(e)}
};/*** 添加字段到指定表* @param addObj 需要添加的对象字段,例:{ name: 'name', age: 20 }* @param tableName 数据库表名* @param callBack 回调函数*/
let add = async function (addObj, tableName, callBack) {try {let ps = new mssql.PreparedStatement(await poolConnect);let sql = "insert into " + tableName + "(";if (addObj != "") {for (let index in addObj) {if (typeof addObj[index] == "number") {ps.input(index, mssql.Int);} else if (typeof addObj[index] == "string") {ps.input(index, mssql.NVarChar);}sql += index + ",";}sql = sql.substring(0, sql.length - 1) + ") values(";for (let index in addObj) {if (typeof addObj[index] == "number") {sql += addObj[index] + ",";} else if (typeof addObj[index] == "string") {sql += "'" + addObj[index] + "'" + ",";}}}sql = sql.substring(0, sql.length - 1) + ") SELECT @@IDENTITY id"; // 加上SELECT @@IDENTITY id才会返回idps.prepare(sql, function (err) {if (err) console.log(err);ps.execute(addObj, function (err, recordset) {callBack(err, recordset);ps.unprepare(function (err) {if (err)console.log(err);});});});} catch (e) {console.log(e)}
};/*** 更新指定表的数据* @param updateObj 需要更新的对象字段,例:{ name: 'name', age: 20 }* @param whereObj 需要更新的条件,例: { id: id }* @param tableName 数据库表名* @param callBack 回调函数*/
let update = async function (updateObj, whereObj, tableName, callBack) {try {let ps = new mssql.PreparedStatement(await poolConnect);let sql = "update " + tableName + " set ";if (updateObj != "") {for (let index in updateObj) {if (typeof updateObj[index] == "number") {ps.input(index, mssql.Int);sql += index + "=" + updateObj[index] + ",";} else if (typeof updateObj[index] == "string") {ps.input(index, mssql.NVarChar);sql += index + "=" + "'" + updateObj[index] + "'" + ",";}}}sql = sql.substring(0, sql.length - 1) + " where ";if (whereObj != "") {for (let index in whereObj) {if (typeof whereObj[index] == "number") {ps.input(index, mssql.Int);sql += index + "=" + whereObj[index] + " and ";} else if (typeof whereObj[index] == "string") {ps.input(index, mssql.NVarChar);sql += index + "=" + "'" + whereObj[index] + "'" + " and ";}}}sql = sql.substring(0, sql.length - 5);ps.prepare(sql, function (err) {if (err)console.log(err);ps.execute(updateObj, function (err, recordset) {callBack(err, recordset);ps.unprepare(function (err) {if (err)console.log(err);});});});} catch (e) {console.log(e)}
};/*** 删除指定表字段* @param whereSql 要删除字段的条件语句,例:'where id = @id'* @param params 参数,用来解释sql中的@*,例如: { id: id }* @param tableName 数据库表名* @param callBack 回调函数*/
let del = async function (whereSql, params, tableName, callBack) {try {let ps = new mssql.PreparedStatement(await poolConnect);let sql = "delete from " + tableName + " ";if (params != "") {for (let index in params) {if (typeof params[index] == "number") {ps.input(index, mssql.Int);} else if (typeof params[index] == "string") {ps.input(index, mssql.NVarChar);}}}sql += whereSql;ps.prepare(sql, function (err) {if (err)console.log(err);ps.execute(params, function (err, recordset) {callBack(err, recordset);ps.unprepare(function (err) {if (err)console.log(err);});});});} catch (e) {console.log(e)}
};exports.config = conf;
exports.del = del;
exports.select = select;
exports.update = update;
exports.querySql = querySql;
exports.selectAll = selectAll;
exports.add = add;

4.在api/user.js下写接口代码

//user.js
const express = require('express');
const db = require('../mssql.js');
const moment = require('moment');
const router = express.Router();/* GET home page. */
router.get('/medicineList', function (req, res, next) {//查询某表下的全部数据db.selectAll('medicineList', function (err, result) {res.send(result.recordset)});
});
router.get('/medicineAssess', function (req, res, next) {db.selectAll('medicineAssess', function (err, result) {res.send(result.recordset)});
});
router.get('/medicineAsk', function (req, res, next) {db.selectAll('medicineAsk', function (err, result) {res.send(result.recordset)});
});
router.get('/diseaseList', function (req, res, next) {db.selectAll('diseaseList', function (err, result) {res.send(result.recordset)});
});
router.get('/diseaseMedicine', function (req, res, next) {db.selectAll('diseaseMedicine', function (err, result) {res.send(result.recordset)});
});
router.get('/user', function (req, res, next) {db.selectAll('user', function (err, result) {res.send(result.recordset)});
});
router.get('/admin', function (req, res, next) {db.selectAll('admin', function (err, result) {res.send(result.recordset)});
});
router.post('/delete', function (req, res, next) {//删除一条id对应的userInfo表的数据const { UserId } = req.bodyconst id = UserIddb.del("where id = @id", { id: id }, "userInfo", function (err, result) {console.log(result, 66);res.send('ok')});
});
router.post('/update/:id', function (req, res, next) {//更新一条对应id的userInfo表的数据var id = req.params.id;var content = req.body.content;db.update({ content: content }, { id: id }, "userInfo", function (err, result) {res.redirect('back');});
});module.exports = router;

5.在server.js中配置启动文件

//1.导入模块
const express = require('express')//2.创建服务器
let server = express()
server.use(express.urlencoded()) //中间件要写在启动文件里面const cors = require('cors')
server.use(cors())const user = require('./api/user.js')server.use('/', user)//3.开启服务器
server.listen(8002, () => {console.log('服务器已启动,在端口号8002')
})

6.启动服务器

cmd到server.js所在的目录下输入:

nodemon server.js

7.用postman测试接口

http://www.khdw.cn/news/53531.html

相关文章:

  • 游戏下载网站 wordpressaso关键词优化工具
  • 给领导发网站建设可行性方案邮件怎么写百度高级搜索技巧
  • 浙江网站设计 site宁波优化网站排名软件
  • 福州市交通建设集团有限公司 网站营销型企业网站案例
  • 网站开发公司需要哪些资质搜索引擎优化的作用
  • 做flash网站广州网站建设费用
  • 廊坊建网站外包买卖交易平台
  • 怎么描述网站主页做的好全球网站排名前100
  • 浪起科技做的网站怎么样网络推广 公司 200个网站
  • dw网站制作流程百度网页版主页
  • 衡水如何做企业网站竞价推广营销
  • 私服网站去哪买空间啊公司网站域名续费一年多少钱
  • wordpress默认登录地址修改优化设计七年级下册语文答案
  • 泉州网站建站公司网站搜索引擎推广
  • 软件开发和网站开发区别上海自动seo
  • 如何做古诗词网站百度收录入口
  • wordpress图片压缩软件旺道优化软件
  • 一个空间可以做多个网站吗网络软营销
  • 济南网站制作0531soso什么软件可以刷网站排名
  • 网站建设中国站需求分析报告个人seo外包
  • 怎么做加密网站网络营销的主要传播渠道是
  • wordpress支持PHP吗seo公司是什么意思
  • 青岛做网站多少钱站长素材免费下载
  • 宜昌营销型网站建设郑州百度快照优化排名
  • 中天建设集团有限公司第九建设公司优化seo方案
  • seo网站推广推荐人工智能的关键词
  • 创建自己的网站需要多少钱广州百度推广客服电话多少
  • 浏阳做网站报价网络服务器配置与管理
  • 做网站密云网店怎么推广和宣传
  • 高清图片素材网站免费百度收录规则2022