加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

REST正则表达式的用法

发布时间:2020-12-14 01:27:21 所属栏目:百科 来源:网络整理
导读:1:@Path上定义的参数,可以使用正则表达式 如:@Path("users/{username: [a-zA-Z][a-zA-Z_0-9]*}") 此处,如果用户输出的参数不匹配,就会报404(Not Found)错误。 2: 顺序作用域 /** *顺序作用域br * Http 方法: GET br * API 路径: /rest/test/{begeinM

1:@Path上定义的参数,可以使用正则表达式


如:@Path("users/{username: [a-zA-Z][a-zA-Z_0-9]*}")

此处,如果用户输出的参数不匹配,就会报404(Not Found)错误。


2:顺序作用域

/**
*顺序作用域<br>
* Http 方法: GET <br>
* API 路径: /rest/test/{begeinMonth:d+},{begeinYear:d+}-{endMonth:d+},{endYear:d+}<br>
* 方 法 名: test3 <br>
* 返回的MIME媒体类型:@Produces("application/json;charset=utf-8")<br>
* @return javax.ws.rs.core.Response
* @throws Throwable
*/
@GET
@Path("{begeinMonth:d+},{endYear:d+}")
@Produces("application/json;charset=utf-8")
public Response test3(@PathParam("begeinMonth") String begeinMonth,
@PathParam("begeinYear") String begeinYear,
@PathParam("endMonth") String endMonth,
@PathParam("endYear") String endYear) throws Throwable {
return Response.status(200).entity(begeinYear + "-"+endMonth+"至" + endYear+"-"+endMonth).build();
}

//d+表示参数为数字,并且必须出现一次!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读