如果我有以下控制器指定如何处理SQL查询:
app.controller('sqlController', ['$scope', '$http','$q', function ($scope, $http, $q) {
$scope.executeSql = function () {
$http.post(apiHost + '/sql/query', {sql: $scope.sql,pageNo:$scope.curPageNo}).then(function (res) {
if(res.data.result==='error'){
return alert(res.data.errmsg)
}
$scope.gridOptions.data = res.data.data;
$scope.gridOptions.columnDefs = []
$scope.pageSize = res.data.pageSize;
$scope.pageNo = res.data.pageNo;
$scope.count = res.data.count;
var cols = res.data.data[0];
var def = $scope.gridOptions.columnDefs;
for(var col in cols){
def.push({name:col, minWidth: '100'});
}
})
}
$scope.export = function(){
var deferred = $q.defer();
$http({
url:apiHost+"/sql/query",
method:'POST',
data:{sql:$scope.sql,pageSize:99999}
}).success(function(res){
deferred.resolve(res.data);
}).error(function(err){
deferred.reject(err);
});
return deferred.promise;
};
$scope.gridOptions = {
data: [],
columnDefs: []
};
}])

有点像?:
POST /sql/query HTTP/1.1
Host: myhost.com
Proxy-Connection: keep-alive
Content-Length: 0
Accept: application/json, text/plain, */*
User-Agent: some user agent
Content-Type: application/json;charset=UTF-8
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,cs;q=0.6