@H_301_1@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+表示参数为数字,并且必须出现一次!
原文链接:https://www.f2er.com/regex/360844.html