流浪少年  
个人网站 http://112.25.151.114:8098/MyWeb/main
var express = require('express');
var router = express.Router();
var url = require('url');
var mysql = require('mysql');
//配置模块
var settings = require('../DbConnection/dbconnection');
//连接数据库
var connection = mysql.createConnection(settings.db);
connection.connect();
router.get('/', function (req, res, next) {
var params = url.parse(req.url, true).query;
console.log("id" + params.id);
var sql = "select * from product";
connection.query(sql, function (error, data) {
console.log(error);
if (error) {
var result = {
"status": "500",
"message": "服务器错误"
}
return res.jsonp(result);
}
else{
var result = {
"status": "200",
"message": "success",
data:data
}
return res.jsonp(result);
}
})
});
module.exports = router;
返回数据为

 


posted on 2017-12-15 12:54  流浪少年  阅读(5197)  评论(0编辑  收藏  举报