跳到主要内容

脚本工具

it - 当前规则的应用对象

  • it 表示当前规则的应用对象(少数规则没有应用对象)
  • 应用对象只提供方法即it.method()✅,不提供属性it.property❎

对于 class(类)、method(方法/API)、field(字段/属性)、param(参数)都支持如下方法

方法返回值描述示例
name()string名称it.name()
hasAnn("annotation_name")boolean是否有指定注解it.hasAnn("org.springframework.web.bind.annotation.RequestBody")
ann("annotation_name")string获取指定注解值(默认 value)it.ann("org.springframework.web.bind.annotation.RequestBody")
ann("annotation_name","attr")string获取指定注解中的指定参数值it.ann("org.springframework.web.bind.annotation.RequestMapping","path")
annMap("annotation_name")map获取指定注解所有的参数it.annMap("org.springframework.web.bind.annotation.RequestMapping")
annMaps("annotation_name")map[]获取指定可重复注解所有的参数it.annMaps("javax.validation.constraints.Max")
annValue("annotation_name")object获取指定注解值(默认 value),与 ann 不同,会保持原有类型,不强制转换为 stringit.annValue("org.springframework.web.bind.annotation.RequestBody")
annValue("annotation_name","attr")object获取指定注解中的指定参数值,与 ann 不同,会保持原有类型,不强制转换为 stringit.annValue("org.springframework.web.bind.annotation.RequestMapping","path")
doc()string获取注释值it.doc()
doc("tag")string获取注释 tag 值(不需要加@)it.doc("return")
docs("tag")array获取多个注释 tag 值(不需要加@)it.docs("see")
doc("tag","subTag")string获取二级注释 tag 值it.doc("param","a")
hasDoc("tag")string是否有指定注释 tagit.hasDoc("ignore")
hasModifier("modifier")string是否有指定修饰it.hasModifier("public")
modifiers()string获取所有修饰it.modifiers()
sourceCode()string获取当前对象源码it.sourceCode()
defineCode()string获取当前对象纯定义代码it.defineCode()
contextType()string当前上下文类型 class/field/method/paramit.contextType()

不同的应用对象提供额外的方法

  • class(类)
方法返回值描述示例
methods()method[]类中的所有方法it.methods()
methodCnt()int类中的方法数it.methodCnt()
field()field[]类中的所有字段it.field()
fieldCnt()int类中的字段数it.fieldCnt()
isExtend(superClass)boolean是否继承某个类it.isExtend("some.class.qualifiedName")
isMap()boolean是否为 Mapit.isMap()
isCollection()boolean是否为集合it.isCollection()
isArray()boolean是否为数组it.isArray()
toJson(readGetter)string获取当前类型的 json 字符串it.toJson(true)
toJson5(readGetter)string获取当前类型的json5字符串it.toJson5(true)
  • method(方法/API)
方法返回值描述示例
returnType()class方法返回类型it.returnType()
isVarArgs()boolean是否有不定参it.isVarArgs()
args()param[]方法的所有参数it.args()
argTypes()class[]方法的所有参数类型it.argTypes()
argCnt()int方法参数个数it.argCnt()
containingClass()class方法所属类it.containingClass()
returnJson(needInfer, readGetter)class当前方法返回对象的 json 字符串it.returnJson(true,true)
  • field(字段/属性)
方法返回值描述示例
type()class字段类型it.type()
containingClass()class字段所属类it.containingClass()
jsonName()string字段 json 名it.jsonName()
jsonType()class字段 json 类型(被转换过的)it.jsonType()
  • param(参数)
方法返回值描述示例
type()class参数类型it.type()
isVarArgs()boolean是否为不定参it.isVarArgs()

tool - 主工具类


主要方法

方法返回值描述示例
debug(obj)voiddebug 对象,获取对象所有可用方法tool.debug(tool)
isNullOrEmpty(obj)Boolean判断对象为 null 或空,支持 null、空字符串、空数组、空集合、空 Maptool.isNullOrEmpty(obj)
notNullOrEmpty(obj)Boolean等价于!isNullOrEmptytool.notNullOrEmpty(obj)
asArray(obj)Array将对象转换为数组tool.asArray(obj)
asList(obj)List将对象转换为集合tool.asList(obj)
intersect(any, other)Array取两个对象的交集tool.intersect(any, other)
anyIntersect(any, other)Boolean判断两个对象是否有交集tool.anyIntersect(any, other)
equalOrIntersect(any, other)Boolean判断两个对象是否相同或有交集,与anyIntersect不同的是, 对于两个空对象, 将返回truetool.equalOrIntersect(any, other)
newSet(items...)Set创建 Set 对象tool.newSet("ele1","ele2")
newList(items...)List创建 List 对象tool.newList("ele1","ele2")
newMap()Map创建 Map 对象tool.newMap()
parseJson(json)Object解析 json 字符串tool.parseJson("{"key":"value"}")
toJson(obj)Object对象转 json 字符串groovy:tool.toJson([key:"value"])
js:tool.toJson({key:"value"})
prettyJson(obj)Object对象转 json 字符串(格式化)groovy:tool.prettyJson([key:"value"])
js:tool.prettyJson({key:"value"})
headLine(str)string获取字符串第一行tool.headLine("multi\nline")
capitalize(str)string字符串首字母大写tool.capitalize("words")
uncapitalize(str)string字符串首字母小写tool.uncapitalize("Words")
swapCase(str)string字符串每个字符大小写转换tool.swapCase("WoRdS")
upperCase(str)string字符串全部大写tool.upperCase("words")
lowerCase(str)string字符串全部小写tool.lowerCase("words")
reverse(str)string字符串反转tool.reverse("sdrow")
repeat(str,repeat)string重复指定字符串tool.repeat("x",10)
isNumeric(str)string判断字符串是纯数字tool.isNumeric("123")
toCamelCase(str)string字符串转驼峰式tool.toCamelCase("some words",true)
now()string获取当前时间 格式为:yyyy-MM-dd HH:mm:sstool.now()
now(pattern)string获取当前时间并指定格式tool.now("yyyy-MM-dd")
today()string获取当前时间 格式为:yyyy-MM-ddtool.today()
format()string格视化时间戳tool.format(1000000000000,"yyyy-MM-dd HH:mm:ss")

其他一些方法


isAlpha

Desc:

Checks if the CharSequence contains only Unicode letters.

{@code null} will return {@code false}. An empty CharSequence (length()=0) will return {@code false}.

tool.isAlpha(null)   = false
tool.isAlpha("") = false
tool.isAlpha(" ") = false
tool.isAlpha("abc") = true
tool.isAlpha("ab2c") = false
tool.isAlpha("ab-c") = false

Params:

nametypedesc
strstring

Return:

nametypedesc
object{@code true} if only contains letters, and is non-null

substringBefore

Desc:

Gets the substring before the first occurrence of a separator. The separator is not returned.

A {@code null} string input will return {@code null}. An empty ("") string input will return the empty string. A {@code null} separator will return the input string.

If nothing is found, the string input is returned.

tool.substringBefore(null, *)      = null
tool.substringBefore("", *) = ""
tool.substringBefore("abc", "a") = ""
tool.substringBefore("abcba", "b") = "a"
tool.substringBefore("abc", "c") = "ab"
tool.substringBefore("abc", "d") = "abc"
tool.substringBefore("abc", "") = ""
tool.substringBefore("abc", null) = "abc"

Params:

nametypedesc
strstring
separatorstring

Return:

nametypedesc
stringthe substring before the first occurrence of the separator,
{@code null} if null String input

substringAfter

Desc:

Gets the substring after the first occurrence of a separator. The separator is not returned.

A {@code null} string input will return {@code null}. An empty ("") string input will return the empty string. A {@code null} separator will return the empty string if the input string is not {@code null}.

If nothing is found, the empty string is returned.

tool.substringAfter(null, *)      = null
tool.substringAfter("", *) = ""
tool.substringAfter(*, null) = ""
tool.substringAfter("abc", "a") = "bc"
tool.substringAfter("abcba", "b") = "cba"
tool.substringAfter("abc", "c") = ""
tool.substringAfter("abc", "d") = ""
tool.substringAfter("abc", "") = "abc"

Params:

nametypedesc
strstring
separatorstring

Return:

nametypedesc
stringthe substring after the first occurrence of the separator,
{@code null} if null String input

substringBeforeLast

Desc:

Gets the substring before the last occurrence of a separator. The separator is not returned.

A {@code null} string input will return {@code null}. An empty ("") string input will return the empty string. An empty or {@code null} separator will return the input string.

If nothing is found, the string input is returned.

tool.substringBeforeLast(null, *)      = null
tool.substringBeforeLast("", *) = ""
tool.substringBeforeLast("abcba", "b") = "abc"
tool.substringBeforeLast("abc", "c") = "ab"
tool.substringBeforeLast("a", "a") = ""
tool.substringBeforeLast("a", "z") = "a"
tool.substringBeforeLast("a", null) = "a"
tool.substringBeforeLast("a", "") = "a"

Params:

nametypedesc
strstring
separatorstring

Return:

nametypedesc
stringthe substring before the last occurrence of the separator,
{@code null} if null String input

substringAfterLast

Desc:

Gets the substring after the last occurrence of a separator. The separator is not returned.

A {@code null} string input will return {@code null}. An empty ("") string input will return the empty string. An empty or {@code null} separator will return the empty string if the input string is not {@code null}.

If nothing is found, the empty string is returned.

tool.substringAfterLast(null, *)      = null
tool.substringAfterLast("", *) = ""
tool.substringAfterLast(*, "") = ""
tool.substringAfterLast(*, null) = ""
tool.substringAfterLast("abc", "a") = "bc"
tool.substringAfterLast("abcba", "b") = "a"
tool.substringAfterLast("abc", "c") = ""
tool.substringAfterLast("a", "a") = ""
tool.substringAfterLast("a", "z") = ""

Params:

nametypedesc
strstring
separatorstring

Return:

nametypedesc
stringthe substring after the last occurrence of the separator,
{@code null} if null String input

substringBetween

Desc:

Gets the String that is nested in between two instances of the same String.

A {@code null} input String returns {@code null}. A {@code null} tag returns {@code null}.

tool.substringBetween(null, *)            = null
tool.substringBetween("", "") = ""
tool.substringBetween("", "tag") = null
tool.substringBetween("tagabctag", null) = null
tool.substringBetween("tagabctag", "") = ""
tool.substringBetween("tagabctag", "tag") = "abc"

Params:

nametypedesc
strstring
tagstring

Return:

nametypedesc
stringthe substring, {@code null} if no match

substringBetween

Desc:

Gets the String that is nested in between two Strings. Only the first match is returned.

A {@code null} input String returns {@code null}. A {@code null} open/close returns {@code null} (no match). An empty ("") open and close returns an empty string.

tool.substringBetween("wxbyz", "", "") = "b"
tool.substringBetween(null, *, *) = null
tool.substringBetween(*, null, *) = null
tool.substringBetween(*, *, null) = null
tool.substringBetween("", "", "") = ""
tool.substringBetween("", "", "]") = null
tool.substringBetween("", "", "") = null
tool.substringBetween("yabcz", "", "") = ""
tool.substringBetween("yabcz", "y", "z") = "abc"
tool.substringBetween("yabczyabcz", "y", "z") = "abc"

Params:

nametypedesc
strstring
openstring
closestring

Return:

nametypedesc
stringthe substring, {@code null} if no match

substringsBetween

Desc:

Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.

A {@code null} input String returns {@code null}. A {@code null} open/close returns {@code null} (no match). An empty ("") open/close returns {@code null} (no match).

tool.substringsBetween("abc", "", "") = "a","b","c"
tool.substringsBetween(null, *, *) = null
tool.substringsBetween(*, null, *) = null
tool.substringsBetween(*, *, null) = null
tool.substringsBetween("", "", "") =

Params:

nametypedesc
strstring
openstring
closestring

Return:

nametypedesc
arraya String Array of substrings, or {@code null} if no match
string

split

Desc:

Splits the provided text into an array, using whitespace as the separator. Whitespace is defined by Character#isWhitespace(char).

The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.

A {@code null} input String returns {@code null}.

tool.split(null)       = null
tool.split("") =
tool.split("abc def") = "abc", "def"
tool.split("abc def") = "abc", "def"
tool.split(" abc ") = "abc"

Params:

nametypedesc
strstring

Return:

nametypedesc
arrayan array of parsed Strings, {@code null} if null String input
string

split

Desc:

Splits the provided text into an array, separators specified. This is an alternative to using StringTokenizer.

The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.

A {@code null} input String returns {@code null}. A {@code null} separatorChars splits on whitespace.

tool.split(null, *)         = null
tool.split("", *) =
tool.split("abc def", null) = "abc", "def"
tool.split("abc def", " ") = "abc", "def"
tool.split("abc def", " ") = "abc", "def"
tool.split("ab:cd:ef", ":") = "ab", "cd", "ef"

Params:

nametypedesc
strstring
separatorCharsstring

Return:

nametypedesc
arrayan array of parsed Strings, {@code null} if null String input
string

regex - 正则工具


getGroup0

Desc:

return the group 0 value($0) if matched otherwise null if not matched

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
string

getGroup1

Desc:

return the group 1 value($1) if matched otherwise null if not matched

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
string

get

Desc:

return the special group value if matched otherwise null if not matched

Params:

nametypedesc
regexstring
contentstring
groupIndexinteger

Return:

nametypedesc
string

getAllGroups

Desc:

return all group value as List if matched otherwise null if not matched

Params:

nametypedesc
patternstring
contentstring

Return:

nametypedesc
array
string

Params:

nametypedesc
regexstring
contentstring
templatestring

Return:

nametypedesc
string

delFirst

Desc:

Remove the first subString of the input String that matches the pattern with the given replacement string.

Params:

nametypedesc
patternstring
contentstring

Return:

nametypedesc
string

delAll

Desc:

Remove the first subString of the input String that matches the pattern

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
string

delBefore

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
string

findAllGroup0

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
array
string

findAllGroup1

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
array
string

findAll

Params:

nametypedesc
regexstring
contentstring
groupinteger

Return:

nametypedesc
array
string

findAll

Params:

nametypedesc
patternobject
- patternstringThe original regular-expression pattern string.
- flagsintegerThe original pattern flags.
contentstring
groupinteger

Return:

nametypedesc
array
string

count

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
integer

contains

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
object

isMatch

Params:

nametypedesc
regexstring
contentstring

Return:

nametypedesc
object

replaceAll

Params:

nametypedesc
contentstring
regexstring
replacementTemplatestring

Return:

nametypedesc
string

escape

Desc:

escape for Regex keywords

Params:

nametypedesc
contentstring

Return:

nametypedesc
string

logger - 日志工具类

可以打印日志到控制台, 受日志级别设置控制, 部分级别的日志会被忽略不显示


方法返回值描述示例
log(str)void打印日志logger.log("some log")
trace(str)void打印日志(日志级别 trace)logger.trace("some log")
debug(str)void打印日志(日志级别 debug)logger.debug("some log")
info(str)void打印日志(日志级别 info)logger.info("some log")
warn(str)void打印日志(日志级别 warn)logger.warn("some log")
error(str)void打印日志(日志级别 error)logger.error("some log")

helper - 特殊帮助类

主要方法

方法返回值描述示例
findClass(str)class获取类, 类似 Class.forName()helper.findClass("java.lang.String")
resolveLink(str)class解析字符串中的linkhelper.resolveLink("{@link java.lang.String}")
resolveLinks(str)array<class/method/field>解析字符串中的所有linkhelper.resolveLink("{@link java.lang.String},{@link java.lang.Long}")

httpClient - HTTP 相关帮助类

主要方法

方法返回值描述示例
cookieStore()cookieStore获取 cookie 管理器httpClient.cookieStore()
request()request创建 requesthttpClient.request()
delete()request创建request,并设置methodDELETEhttpClient.delete()
delete(str)request创建request,并设置methodDELETE、设置urlhttpClient.delete("http://www.apifox.com/")
get()request创建request,并设置methodGEThttpClient.get()
get(str)request创建request,并设置methodGET、设置urlhttpClient.get("http://www.apifox.com/")
options()request创建request,并设置methodOPTIONShttpClient.options()
options(str)request创建request,并设置methodOPTIONS、设置urlhttpClient.options("http://www.apifox.com/")
post()request创建request,并设置methodPOSThttpClient.post()
post(str)request创建request,并设置methodPOST、设置urlhttpClient.post("http://www.apifox.com/")
put()request创建request,并设置methodPUThttpClient.put()
put(str)request创建request,并设置methodPUT、设置urlhttpClient.put("http://www.apifox.com/")
trace()request创建request,并设置methodTRACEhttpClient.trace()
trace(str)request创建request,并设置methodTRACE、设置urlhttpClient.trace("http://www.apifox.com/")

request

  • 可以由httpClient创建

主要方法有

方法返回值描述示例
call()response发起http请求request.call()
method()string获取当前请求的methodrequest.method()
method(string)request设置当前请求的methodrequest.method("POST")
url()string获取当前请求的urlrequest.url()
url(string)request设置当前请求的urlrequest.url("http://www.apifox.com/")
body()object获取当前请求体request.body()
body(object)request设置当前请求体request.body({"name":"admin"})
contentType()string获取当前请求的Content-typerequest.contentType()
contentType(string)string设置当前请求的Content-typerequest.contentType("application/json")
querys()request获取所有的 query 参数request.querys()
query(string, string)request设置 query(请求时将被追加在 url 后)request.query("name","Tom")
params()array<param>获取所有参数request.params()
params(string)array<param>获取指定参数名的所有参数request.params("name")
containsParam(string)bool判断当前请求是否有指定请求参数request.containsParam("name")
fileParam(string, string)request设置一个文件参数request.fileParam("file","/xxx/xxx/xxxx.xxx")
firstParam(string)param获取第一个请求参数(注意返回值是 param,包含参数名/参数值/参数类型[text/file])request.firstParam("name")
firstParamValue(string)param获取第一个请求参数值request.firstParamValue("name")
lastParam(string)param获取最后一个请求参数(注意返回值是 param,包含参数名/参数值/参数类型[text/file])request.lastParam("name")
lastParamValue(string)param获取最后一个请求参数值request.lastParamValue("name")
param(string, string)request设置paramrequest.param("name","Tom")
paramValues(string)array<string>获取指定参数所有值request.paramValues("name")
header(string, string)request设置headerrequest.header("Content-type","application/json")
headers()array<header>获取所有的headerrequest.headers()
headers(string)array<string>获取指定header所有值request.headers("Content-type")
containsHeader(string)bool判断当前请求是否有指定headerrequest.containsHeader("token")
firstHeader(string)string获取第一个 header 参数request.firstHeader("Content-type")
lastHeader(string)string获取最后一个 header 参数request.lastHeader("Content-type")
setHeader(string, string)request移除当前header名称的所有值,并设置headerrequest.setHeader("Content-type","application/json")
removeHeader(string, string)request移除指定header名称的指定值request.removeHeader("Content-type","application/json")
removeHeaders(string)request移除当前header名称的所有值request.removeHeaders("Content-type")

response

  • 可以由request.call()得到

主要方法有

方法返回值描述示例
discard()void丢弃这次请求的结果, 重新发起此请求response.discard()
code()int响应 coderesponse.code()
string()string响应内容response.string()
contentType()string响应的 contentTyperesponse.contentType()
headers()array<header>获取所有的headerresponse.headers()
headers(string)array<string>获取指定header所有值response.headers("Content-type")
containsHeader(string)bool判断当前响应是否有指定headerresponse.containsHeader("token")
firstHeader(string)string获取第一个 header 参数response.firstHeader("Content-type")
lastHeader(string)string获取第一个 header 参数response.lastHeader("Content-type")
request()request获取得到此响应的requestresponse.request()

cookieStore

  • 可以由httpClient.cookieStore()获得

主要方法有

方法返回值描述示例
addCookie(cookie)void添加一个 cookiehttpClient.cookieStore().addCookie(cookie)
addCookies(cookies)void添加多个 cookiehttpClient.cookieStore().addCookies(cookies)
clear()void清除 cookiehttpClient.cookieStore().clear()
cookies()array<cookie>获得当前的 cookieshttpClient.cookieStore().cookies()
newCookie()cookie创建一个cookie,注意:并不会自动添加到cookieStore中, 需要手动调用addCookie加入httpClient.cookieStore().newCookie()

localStorage 本地存储

  • 未指定分组时所有操作都在默认分组
  • localStorage默认是存储在用户根目录下,可以跨项目读写,如果需要仅在当前项目读写,所有的操作都需要指定一个 group.
  • 注意:set(key,value)中的valueget(key)得到的value并非同一对象.
def obj = ["a":"b"]
localStorage.set("key",obj)
localStorage.get("key")["a"]=c //这里对 get("key")得到的对象进行赋值不会影响到原始的 obj
obj["a"] == "b" //obj 还是["a":"b"]

主要方法

方法返回值描述示例
set(key,value)void设置一个键值localStorage.set("key","value")
set(group,key,value)void设置一个键值(指定分组)localStorage.set("groupA","key","value")
get(key)object获取一个设置的键值localStorage.get("key")
get(group,key)object获取一个设置的键值(指定分组)localStorage.get("groupA","key")
remove(key)void删除一个设置的键值localStorage.remove("key")
remove(group,key)void删除一个设置的键值(指定分组)localStorage.remove("groupA","key")
clear()void移除所有设置的键值(仅默认分组)localStorage.clear()
clear(group)void移除所有设置的键值(指定分组)localStorage.clear("groupA")
keys()array<object>获取所有设置的键值(仅默认分组)localStorage.keys()
keys(group)array<object>获取所有设置的键值(指定分组)localStorage.keys("groupA")

config 配置读取工具

主要方法

方法返回值描述示例
get(key)string获取配置中的一个值config.get("key")
getValues(key)array<string>获取配置中的多个值config.getValues("key")
resolveProperty(str)string解析字符串中的占位符config.resolveProperty("${key}")

api - 当前导出的 API

  • 应用对象只提供方法即api.method()✅, 不提供属性api.property❎

主要方法

方法返回值描述示例
name()stringapi 名称api.name()
setName("name")void设置 api 名称api.setName("xxx")
desc()stringapi 描述api.desc()
setDesc("desc")void设置 api 描述api.setDesc("这是一个...")
appendDesc("desc")void追加 api 描述api.appendDesc("这是一个...")
method()stringapi 的 Http Methodapi.method()
setMethod("method")void设置 api 的 Http Methodapi.setMethod("POST")
setMethodIfMissed("method")void如果 api 的 Http Method 不存在则设置为指定值api.setMethodIfMissed("POST")
path()stringapi 路径, 如果此 api 有多个路径, 返回第一个api.path()
paths()string[]api 路径数组api.paths()
setPath("path")void设置 api 路径api.setPath("/a/b/c")
setPaths(["path"*])void设置 api 路径api.setPaths(["/a/b/c"."/a/b/d"])
bodyAttr()stringapi body 的描述api.bodyAttr()
setBody(object)void设置 api bodyapi.setBody(["x":"y"])
setBodyClass("class")void通过类型名设置 api bodyapi.setBodyClass("com.itangcent.XxxxDTO")
setJsonBody(object,"attr")void设置 api bodyapi.setBody(["x":"y"],"描述")
addModelAsParam(object)void设置 api 参数api.addModelAsParam(["x":"y"])
addModelClass("class")void通过类型名设置 api 参数api.addModelClass("com.itangcent.XxxxDTO")
addParam(paramName,defaultVal,desc)void增加参数api.addParam("name","tang","user name")
addParam(paramName,defaultVal,required,desc)void增加参数api.addParam("name","tang",false,"user name")
setParam(paramName,defaultVal,required,desc)void设置参数(如果参数已存在会被覆盖)api.setParam("name","tang",false,"user name")
addFormParam(paramName,defaultVal,desc)void增加表单参数api.addFormParam("name","tang","user name")
addFormParam(paramName,defaultVal,required,desc)void增加表单参数api.addFormParam("name","tang",false,"user name")
setFormParam(paramName,defaultVal,required,desc)void设置表单参数(如果参数已存在会被覆盖)api.setFormParam("name","tang",false,"user name")
addFormFileParam(paramName,required,desc)void增加文件类型的表单参数api.setFormParam("avatar",false,"user's avatar")
setFormFileParam(paramName,required,desc)void增加文件类型的表单参数(如果参数已存在会被覆盖)api.setFormFileParam("avatar",false,"user's avatar")
addPathParam(paramName,desc)void增加路径参数api.addPathParam("id","user id")
addPathParam(paramName,value,desc)void增加路径参数api.addPathParam("id","1","user id")
setPathParam(paramName,value,desc)void设置路径参数(如果参数已存在会被覆盖)api.setPathParam("id","1","user id")
headers()array<Header>获取 api 所有的 Headerapi.headers()
header("name")Header获取 api 中指定名称的 Headerapi.header("Content-Type")
headers("name")array<Header>获取 api 中指定名称的所有 Headerapi.headers("token")
removeHeader("name")Header移除 api 中指定名称的 Headerapi.removeHeader("token")
addHeader("name","value")void增加 Headerapi.addHeader("Content-Type","application/json")
addHeaderIfMissed("name","value")void如果指定名称的 Header 不存在则增加此 Headerapi.addHeaderIfMissed("Content-Type","application/json")
addHeader("name","value",required,"desc")void增加 Headerapi.addHeader("Content-Type","application/json",true,"header which is used to indicate the original media type of the resource")
setHeader("name","value",required,"desc")void设置 Header(如果 Header 已存在会被覆盖)api.setHeader("Content-Type","application/json",true,"header which is used to indicate the original media type of the resource")
以下为response相关的方法---------------
setResponseBody(body)void设置 api 响应的 body
bodyType 默认为 rawapi.setResponseBody(["x":"y"])
setResponseBody("bodyType",body)void设置 api 响应的 body
bodyType:raw/json/xmlapi.setResponseBody("json",["x":"y"])
setResponseBodyClass("bodyClass")void通过类型名设置 api 响应的 body
bodyType 默认为 rawapi.setResponseBody("com.itangcent.XxxxVO")
setResponseBodyClass("bodyType","bodyClass")void通过类型名设置 api 响应的 body
bodyType:raw/json/xmlapi.setResponseBody("json","com.itangcent.XxxxVO")
setResponseCode(code)void设置响应 codeapi.setResponseCode(200)
appendResponseBodyDesc("bodyDesc")void设置响应描述api.appendResponseBodyDesc("user info")
addResponseHeader("name","value")void增加响应 Headerapi.addResponseHeader("Content-Type","application/json")
addResponseHeader("name","value",required,"desc")void增加响应 Headerapi.addResponseHeader("Content-Type","application/json",true,"header which is used to indicate the original media type of the resource")
setResponseHeader("name","value",required,"desc")void设置响应 Headerapi.setResponseHeader("Content-Type","application/json",true,"header which is used to indicate the original media type of the resource")