0

我正在编写一个 REST 组件,但是当我不想为参数传递参数时遇到了困难。我的代码和 URL(PATH 样式)如下所示。

组件定义:

<cfcomponent rest="true" restPath="SearchRestAPI">
<cffunction name="restaurantResults" access="remote" httpMethod="get" 
            output="false" returntype="Query" produces="application/json"
            restPath="Search/{city : ([a-zA-Z])*}/{address}/{type}">

<cfargument name="city" default="" type="string" restargsource="path">
<cfargument name="address" default="" type="string" restargsource="path"> 
<cfargument name="type" default="" type="string" restargsource="path">

调用 URL/Path 以使用 REST 服务。请注意,我不想为类型参数发送任何值,因此路径末尾有双斜杠:

http://localhost:8502/backend/section/SearchResAPI/Search/Calcutta/Lindsay Street//

但这会引发“未找到”错误。任何建议将不胜感激。

4

1 回答 1

0

我不确定这个 ColdFusion 功能,但看起来“restPath”适用于正则表达式(您在捕获 city 参数时已经在使用它

([a-zA-Z])* // your city parameter matches the specified character sets zero or more times.

与上述类似,您可以尝试:

restPath="Search/{city : ([a-zA-Z])*}/{address}/{type: ([a-zA-Z])*}"

这是一个 ColdFusion 页面,其中也有一些示例(在页面中搜索“restPath”): https ://wikidocs.adobe.com/wiki/display/coldfusionen/cfcomponent

于 2015-08-13T21:11:46.693 回答