【发布时间】:2016-04-09 16:59:51
【问题描述】:
我正在使用 AngularJS 和 NodeJS/Express 设计一个二手车网站。数据库是 MySQL(所以不是一个 MEAN 堆栈)。
我对 Angular 非常熟悉,但这是我第一次使用 Express(过去我使用过 JAX-RS)。
我只发送一两个参数没有问题,例如
app.get('/api/images/:vehicleId', function (request, response) {
images.getThumbnailImage(request, response, connection, request.params.vehicleId);
});
但我不确定如何使用多个参数前进,其中一些是可选的。
客户端是使用 TypeScript 构建的。表单数据是通过 TypeScript 对象收集的,但我不确定发送多个参数的最佳做法是什么。
我想到的选项是:
1)。发送对象,然后使用它来构建查询:
return this.$http({
method: 'POST',
url: this.API_ADDRESS + 'vehicles/',
data: vehicleSearchModel,
headers: {
'Content-Type': 'application/json'
}
}).then((response: any) => {
return response.data;
});
并使用body-parser从body中检索它,即
request.body.data (or something similar)
或
2)。在 url 中发送多个参数,即
app.get('/api/vehicles/:make/:model/:bodyStyle/:fuelType/:transmission/:minPrice/:maxPrice/:minYear/:maxYear/:counties', function (request, response) {
//Do something with request.params!!!
});
请指教。
【问题讨论】:
标签: mysql angularjs node.js express