1

ExpressJS在服务器和Android客户端上使用

我想知道如何在服务器中执行此操作::

  • 假设我有一个listView大学列表,我JSON使用下面显示的 Express 程序获得数据。

  • 现在Android已经OnClick用于识别位置 listview

  • 如何动态获取android客户端的JSON(如果我点击一行,我想在服务器上动态进行数据库查询,以便动态生成JSON URL)

  • 我没有发布 android 代码,因为我认为修改是在服务器端,但是android developers谁使用过ExpressJS或者NodeJS 也会对此有想法


我需要在服务器上进行哪些代码更改?

我应该寻找什么概念来实现这个功能?


服务器上的我的 Express 程序 ::

var express = require('express')
  , async = require('async')
  , http = require('http')
  , mysql = require('mysql'); 

var app = express();

var connection = mysql.createConnection({
    host: 'localhost',
    user: 'xxx',
    password: "xxx",
    database: 'collages'
});

connection.connect(); 

// all environments
app.set('port', process.env.PORT || 1232);

//
//REQUEST FOR FIRST REQUEST
//

app.get('/',function(request,response){
    var name_of_Collages, RestaurantTimings;

    async.series( [
        // Get the first table contents
        function ( callback ) {
            connection.query('SELECT * FROM collagenames', function(err, rows, fields)
                {
                        console.log('Connection result error '+err);
                        name_of_Collages = rows;
                        callback();
                });
        },
        // Get the second table contents
        function ( callback ) {
        connection.query('SELECT * FROM RestaurantTimings', function(err, rows, fields)

            {
                    console.log('Connection result error '+err);
                    RestaurantTimings = rows;
                    callback();
            });
        }

   // Send the response
], function ( error, results ) {
    response.json({
        'Collages' : name_of_Collages,
        'RestaurantTimings' : RestaurantTimings
    });
} );

} );



//
//REQUEST FOR Collage SCREEN
//


app.get('/College1',function(request,response){
    var College1, RestaurantTimings;

    async.series( [
        // Get the first table contents
        function ( callback ) {
            connection.query('SELECT * FROM College1', function(err, rows, fields)
                {
                        console.log('Connection result error '+err);
                        College1 = rows;
                        callback();
                });
        },
        // Get the second table contents
        function ( callback ) {
        connection.query('SELECT * FROM RestaurantTimings', function(err, rows, fields)

            {
                    console.log('Connection result error '+err);
                    RestaurantTimings = rows;
                    callback();
            });
        }

   // Send the response
], function ( error, results ) {
    response.json({
        'College' : College1,
        'RestaurantTimings' : RestaurantTimings
    });
} );


} );



http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

希望我清楚

谢谢,

4

0 回答 0