脚本工具
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 不同,会保持原有类型,不强制转换为 string | it.annValue("org.springframework.web.bind.annotation.RequestBody") |
annValue("annotation_name","attr") | object | 获取指定注解中的指定参数值,与 ann 不同,会保持原有类型,不强制转换为 string | it.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 | 是否有指定注释 tag | it.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/param | it.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 | 是否为 Map | it.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) | void | debug 对象,获取对象所有可用方法 | tool.debug(tool) |
isNullOrEmpty(obj) | Boolean | 判断对象为 null 或空,支持 null、空字符串、空数组、空集合、空 Map | tool.isNullOrEmpty(obj) |
notNullOrEmpty(obj) | Boolean | 等价于!isNullOrEmpty | tool.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 不同的是, 对于两个空对象, 将返回true | tool.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:ss | tool.now() |
now(pattern) | string | 获取当前时间并指定格式 | tool.now("yyyy-MM-dd") |
today() | string | 获取当前时间 格式为:yyyy-MM-dd | tool.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:
name | type | desc |
---|---|---|
str | string |
Return:
name | type | desc |
---|---|---|
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:
name | type | desc |
---|---|---|
str | string | |
separator | string |
Return:
name | type | desc |
---|---|---|
string | the 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:
name | type | desc |
---|---|---|
str | string | |
separator | string |
Return:
name | type | desc |
---|---|---|
string | the 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:
name | type | desc |
---|---|---|
str | string | |
separator | string |
Return:
name | type | desc |
---|---|---|
string | the 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:
name | type | desc |
---|---|---|
str | string | |
separator | string |
Return:
name | type | desc |
---|---|---|
string | the 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:
name | type | desc |
---|---|---|
str | string | |
tag | string |
Return:
name | type | desc |
---|---|---|
string | the 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:
name | type | desc |
---|---|---|
str | string | |
open | string | |
close | string |
Return:
name | type | desc |
---|---|---|
string | the 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:
name | type | desc |
---|---|---|
str | string | |
open | string | |
close | string |
Return:
name | type | desc |
---|---|---|
array | a 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:
name | type | desc |
---|---|---|
str | string |
Return:
name | type | desc |
---|---|---|
array | an 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:
name | type | desc |
---|---|---|
str | string | |
separatorChars | string |
Return:
name | type | desc |
---|---|---|
array | an 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:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
string |
getGroup1
Desc:
return the group 1 value($1) if matched otherwise null if not matched
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
string |
get
Desc:
return the special group value if matched otherwise null if not matched
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string | |
groupIndex | integer |
Return:
name | type | desc |
---|---|---|
string |
getAllGroups
Desc:
return all group value as List if matched otherwise null if not matched
Params:
name | type | desc |
---|---|---|
pattern | string | |
content | string |
Return:
name | type | desc |
---|---|---|
array | ||
string |
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string | |
template | string |
Return:
name | type | desc |
---|---|---|
string |
delFirst
Desc:
Remove the first subString of the input String that matches the pattern with the given replacement string.
Params:
name | type | desc |
---|---|---|
pattern | string | |
content | string |
Return:
name | type | desc |
---|---|---|
string |
delAll
Desc:
Remove the first subString of the input String that matches the pattern
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
string |
delBefore
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
string |
findAllGroup0
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
array | ||
string |
findAllGroup1
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
array | ||
string |
findAll
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string | |
group | integer |
Return:
name | type | desc |
---|---|---|
array | ||
string |
findAll
Params:
name | type | desc |
---|---|---|
pattern | object | |
- pattern | string | The original regular-expression pattern string. |
- flags | integer | The original pattern flags. |
content | string | |
group | integer |
Return:
name | type | desc |
---|---|---|
array | ||
string |
count
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
integer |
contains
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
object |
isMatch
Params:
name | type | desc |
---|---|---|
regex | string | |
content | string |
Return:
name | type | desc |
---|---|---|
object |
replaceAll
Params:
name | type | desc |
---|---|---|
content | string | |
regex | string | |
replacementTemplate | string |
Return:
name | type | desc |
---|---|---|
string |
escape
Desc:
escape for Regex keywords
Params:
name | type | desc |
---|---|---|
content | string |
Return:
name | type | desc |
---|---|---|
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 | 解析字符串中的link | helper.resolveLink("{@link java.lang.String}") |
resolveLinks(str) | array<class/method/field> | 解析字符串中的所有link | helper.resolveLink("{@link java.lang.String},{@link java.lang.Long}") |
httpClient - HTTP 相关帮助类
主要方法
方法 | 返回值 | 描述 | 示例 |
---|---|---|---|
cookieStore() | cookieStore | 获取 cookie 管理器 | httpClient.cookieStore() |
request() | request | 创建 request | httpClient.request() |
delete() | request | 创建request ,并设置method 为DELETE | httpClient.delete() |
delete(str) | request | 创建request ,并设置method 为DELETE 、设置url | httpClient.delete("http://www.apifox.com/") |
get() | request | 创建request ,并设置method 为GET | httpClient.get() |
get(str) | request | 创建request ,并设置method 为GET 、设置url | httpClient.get("http://www.apifox.com/") |
options() | request | 创建request ,并设置method 为OPTIONS | httpClient.options() |
options(str) | request | 创建request ,并设置method 为OPTIONS 、设置url | httpClient.options("http://www.apifox.com/") |
post() | request | 创建request ,并设置method 为POST | httpClient.post() |
post(str) | request | 创建request ,并设置method 为POST 、设置url | httpClient.post("http://www.apifox.com/") |
put() | request | 创建request ,并设置method 为PUT | httpClient.put() |
put(str) | request | 创建request ,并设置method 为PUT 、设置url | httpClient.put("http://www.apifox.com/") |
trace() | request | 创建request ,并设置method 为TRACE | httpClient.trace() |
trace(str) | request | 创建request ,并设置method 为TRACE 、设置url | httpClient.trace("http://www.apifox.com/") |
request
- 可以由
httpClient
创建
主要方法有
方法 | 返回值 | 描述 | 示例 |
---|---|---|---|
call() | response | 发起http 请求 | request.call() |
method() | string | 获取当前请求的method | request.method() |
method(string) | request | 设置当前请求的method | request.method("POST") |
url() | string | 获取当前请求的url | request.url() |
url(string) | request | 设置当前请求的url | request.url("http://www.apifox.com/") |
body() | object | 获取当前请求体 | request.body() |
body(object) | request | 设置当前请求体 | request.body({"name":"admin"}) |
contentType() | string | 获取当前请求的Content-type | request.contentType() |
contentType(string) | string | 设置当前请求的Content-type | request.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 | 设置param | request.param("name","Tom") |
paramValues(string) | array<string> | 获取指定参数所有值 | request.paramValues("name") |
header(string, string) | request | 设置header | request.header("Content-type","application/json") |
headers() | array<header> | 获取所有的header | request.headers() |
headers(string) | array<string> | 获取指定header 所有值 | request.headers("Content-type") |
containsHeader(string) | bool | 判断当前请求是否有指定header | request.containsHeader("token") |
firstHeader(string) | string | 获取第一个 header 参数 | request.firstHeader("Content-type") |
lastHeader(string) | string | 获取最后一个 header 参数 | request.lastHeader("Content-type") |
setHeader(string, string) | request | 移除当前header 名称的所有值,并设置header | request.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 | 响应 code | response.code() |
string() | string | 响应内容 | response.string() |
contentType() | string | 响应的 contentType | response.contentType() |
headers() | array<header> | 获取所有的header | response.headers() |
headers(string) | array<string> | 获取指定header 所有值 | response.headers("Content-type") |
containsHeader(string) | bool | 判断当前响应是否有指定header | response.containsHeader("token") |
firstHeader(string) | string | 获取第一个 header 参数 | response.firstHeader("Content-type") |
lastHeader(string) | string | 获取第一个 header 参数 | response.lastHeader("Content-type") |
request() | request | 获取得到此响应的request | response.request() |
cookieStore
- 可以由
httpClient.cookieStore()
获得
主要方法有
方法 | 返回值 | 描述 | 示例 |
---|---|---|---|
addCookie(cookie) | void | 添加一个 cookie | httpClient.cookieStore().addCookie(cookie) |
addCookies(cookies) | void | 添加多个 cookie | httpClient.cookieStore().addCookies(cookies) |
clear() | void | 清除 cookie | httpClient.cookieStore().clear() |
cookies() | array<cookie> | 获得当前的 cookies | httpClient.cookieStore().cookies() |
newCookie() | cookie | 创建一个cookie ,注意:并不会自动添加到cookieStore 中, 需要手动调用addCookie 加入 | httpClient.cookieStore().newCookie() |
localStorage 本地存储
- 未指定分组时所有操作都在默认分组
localStorage
默认是存储在用户根目录下,可以跨项目读写,如果需要仅在当前项目读写,所有的操作都需要指定一个 group.- 注意:
set(key,value)
中的value
与get(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() | string | api 名称 | api.name() |
setName("name") | void | 设置 api 名称 | api.setName("xxx") |
desc() | string | api 描述 | api.desc() |
setDesc("desc") | void | 设置 api 描述 | api.setDesc("这是一个...") |
appendDesc("desc") | void | 追加 api 描述 | api.appendDesc("这是一个...") |
method() | string | api 的 Http Method | api.method() |
setMethod("method") | void | 设置 api 的 Http Method | api.setMethod("POST") |
setMethodIfMissed("method") | void | 如果 api 的 Http Method 不存在则设置为指定值 | api.setMethodIfMissed("POST") |
path() | string | api 路径, 如果此 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() | string | api body 的描述 | api.bodyAttr() |
setBody(object) | void | 设置 api body | api.setBody(["x":"y"]) |
setBodyClass("class") | void | 通过类型名设置 api body | api.setBodyClass("com.itangcent.XxxxDTO") |
setJsonBody(object,"attr") | void | 设置 api body | api.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 所有的 Header | api.headers() |
header("name") | Header | 获取 api 中指定名称的 Header | api.header("Content-Type") |
headers("name") | array<Header> | 获取 api 中指定名称的所有 Header | api.headers("token") |
removeHeader("name") | Header | 移除 api 中指定名称的 Header | api.removeHeader("token") |
addHeader("name","value") | void | 增加 Header | api.addHeader("Content-Type","application/json") |
addHeaderIfMissed("name","value") | void | 如果指定名称的 Header 不存在则增加此 Header | api.addHeaderIfMissed("Content-Type","application/json") |
addHeader("name","value",required,"desc") | void | 增加 Header | api.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 默认为 raw | api.setResponseBody(["x":"y"]) | ||
setResponseBody("bodyType",body) | void | 设置 api 响应的 body | |
bodyType:raw/json/xml | api.setResponseBody("json",["x":"y"]) | ||
setResponseBodyClass("bodyClass") | void | 通过类型名设置 api 响应的 body | |
bodyType 默认为 raw | api.setResponseBody("com.itangcent.XxxxVO") | ||
setResponseBodyClass("bodyType","bodyClass") | void | 通过类型名设置 api 响应的 body | |
bodyType:raw/json/xml | api.setResponseBody("json","com.itangcent.XxxxVO") | ||
setResponseCode(code) | void | 设置响应 code | api.setResponseCode(200) |
appendResponseBodyDesc("bodyDesc") | void | 设置响应描述 | api.appendResponseBodyDesc("user info") |
addResponseHeader("name","value") | void | 增加响应 Header | api.addResponseHeader("Content-Type","application/json") |
addResponseHeader("name","value",required,"desc") | void | 增加响应 Header | api.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 | 设置响应 Header | api.setResponseHeader("Content-Type","application/json",true,"header which is used to indicate the original media type of the resource") |