package com.cwteam.demo.version;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.servlet.mvc.condition.RequestCondition;
/**
* @author cwteam
* @date 2017-08-14
* @desc
* 首先,匹配过滤出当前访问接口中是否存在v(1-9),
* 如果存在,继续判断格式是否对,否则报错返回。
* 其次,比较请求地址中版本与控制器中版本,如果
* 请求的版本值大于控制器中版本值,则取控制器版本
* 值继续接口后续访问操作。
*/
public class ApiVerCondition implements RequestCondition<ApiVerCondition> {
private final static Pattern VERSION_PREFIX_PATTERN = Pattern.compile("v(\\d+)/");
private int apiVersion;
public ApiVerCondition(int apiVersion){
this.apiVersion = apiVersion;
}
public ApiVerCondition combine(ApiVerCondition other) {
return new ApiVerCondition(other.getApiVersion());
}
public ApiVerCondition getMatchingCondition(HttpServletRequest request) {
Matcher m = VERSION_PREFIX_PATTERN.matcher(request.getRequestURI());
if(m.find()){
Integer version = Integer.valueOf(m.group(1));
if(version >= this.apiVersion)
return this;
}
return null;
}
public int compareTo(ApiVerCondition other, HttpServletRequest request) {
return other.getApiVersion() - this.apiVersion;
}
public int getApiVersion() {
return apiVersion;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
restapi-version.zip (31个子文件)
restapi-version
.project 1KB
pom.xml 2KB
target
test-classes
m2e-wtp
web-resources
META-INF
maven
com.cwteam
cwteam
pom.xml 2KB
pom.properties 190B
restapi-version
pom.xml 2KB
pom.properties 217B
MANIFEST.MF 107B
classes
com
cwteam
demo
version
ApiVerCondition.class 2KB
ApiRequestMapping.class 2KB
ApiVer.class 511B
action
ApiVerAction.class 1KB
ScanAction.class 124B
app
WebAppConfigInitializer.class 2KB
config
ServletConfig.class 1021B
.settings
.jsdtscope 626B
org.eclipse.wst.common.component 759B
org.eclipse.wst.validation.prefs 48B
org.eclipse.jdt.core.prefs 422B
org.eclipse.wst.common.project.facet.core.xml 245B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.m2e.core.prefs 86B
org.eclipse.wst.jsdt.ui.superType.name 6B
src
test
java
main
resources
java
com
cwteam
demo
version
ApiVerCondition.java 2KB
ApiVer.java 706B
ApiRequestMapping.java 1KB
action
ApiVerAction.java 1KB
ScanAction.java 65B
app
WebAppConfigInitializer.java 2KB
config
ServletConfig.java 906B
webapp
index.jsp 52B
META-INF
.classpath 1KB
共 31 条
- 1
资源评论
- 论坛VIP用户2018-07-25可以参考使用。
云水之路
- 粉丝: 174
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【unity开发】Unity文档的开发人员注释
- 微信小程序-周公解梦.zip
- ijkplayer ffmpeg6.1.1 编译好的so库 arm64
- 免费云注入软件,提供脱壳,云注入等服务,海口市奋斗科技有限公司旗下产业
- YOLOv5+Deepsort+python实现驾驶员分心驾驶行为(疲劳+危险行为)预警监测+源码+文档+视频演示(高分优秀项目
- 海口市奋斗智能科技有限公司旗下的免费影视软件
- 奋斗社区,各种编程大佬资源分享社区
- androidx.media3.exoplayer,libflac库
- java毕业设计 - 药源购物网站(ssm+Vue+说明文档+LW+PPT)
- VNC Viewer手机版远程桌面
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功