SpringMVC里拦截器preHandle里的参数究竟是什么意思

更新时间:2023-06-14 16:14:25 阅读: 评论:0

SpringMVC⾥拦截器preHandle⾥的参数究竟是什么意思
今天我的update接⼝⽼是报错,请求和处理⽅法和create⼀模⼀样。
create接⼝:
@RequestMapping(value = "/oftenTraveller/create", method = {RequestMethod.POST})
public ResponEntity<Respon<OftenTravellerDTO>> createOftenTraveller(HttpServletRequest request, HttpServletRespon respon,                                                              @RequestBody OftenTravellerParam newContent) {
TokenInMemcached token = getTokenInMemcached(request);
String urId = Ur().getId();
newContent.tOwnerId(urId);
Respon<OftenTravellerDTO> resp = new Respon<>();
log.debug("create OftenTraveller :{}", newContent);
OftenTravellerDTO dto = ate(newContent);
resp.tResult(Result.SUCCESS_RESULT);
// to dto
resp.tData(dto);
return new ResponEntity<>(resp, HttpStatus.CREATED);
}
update接⼝:
@RequestMapping(value = "/oftenTraveller/update/{id}", method = {RequestMethod.POST})
public ResponEntity<Respon<OftenTravellerDTO>> updateOftenTraveller(HttpServletRequest request, HttpServletRespon respon,                                                              @PathVariable Long id, @RequestBody OftenTravellerParam updateContent) throw Exception{
Respon<OftenTravellerDTO> resp = new Respon<>();
log.debug("update OftenTraveller id:{} to {}", id, updateContent);
OftenTraveller entity = One(id);
if (entity == null) {
log.warn("OftenTraveller id:{} not found", id);
resp.tResult(Result.FAIL_RESULT);
return new ResponEntity<>(resp, HttpStatus.BAD_REQUEST);
}
updateContent.tId(id);
try {
} catch (Exception e) {
<(e.getMessage(), e);
当兵祝福
throw new Message(),e);
}
oftenTravellerService.update(entity);
// to dto
OftenTravellerDTO dto = DTOUtils.map(entity, OftenTravellerDTO.class);
resp.tData(dto);
resp.tResult(Result.SUCCESS_RESULT);
return new ResponEntity<>(resp, HttpStatus.OK);
}
程序在每次的request拦截器⾥都会被拦截报错:
@Override
public boolean preHandle(HttpServletRequest request,
害羞的味道
HttpServletRespon respon, Object handler) throws Exception {
String handlerValue = String();
String[] methodStringArray = StringUtils.split(handlerValue);
String methodName = methodStringArray[methodStringArray.length - 1];
String apiName = ShortMethodName(methodName);//在这⼉报错
……
太极拳八段锦
报错内容是空指针;
⽽我把handler⾥⾯的内容打印出来,发现:
安全知识答题create:
public org.springframework.http.ResponEntity<com.dto.Respon<com.dto.profile.OftenTravellerD TO>> com.smartprint.ller.v1.ateOftenTraveller(javax.rvlet.http.HttpServletRequest,javax.rvlet.htt p.HttpServletRespon,com.dto.profile.OftenTravellerParam)
update:
public org.springframework.http.ResponEntity<com.dto.Respon<com.dto.profile.OftenTravellerD TO>> com.smartprint.ller.v1.urCenter.OftenCenterController.updateOftenTraveller(javax.rvlet.http.HttpServletRequest,javax.rvlet.ht tp.HttpServletRespon,java.lang.Long,com.dto.profile.OftenTravellerParam) throws java.lang.Exception
联系上⽂:
String apiName = ShortMethodName(methodName);//在这⼉报错从一到十的成语>爱心捐款倡议书
屁股挨打
查看了下ShortMethodName(methodName)
public static String getShortMethodName(String fullName) {
int openBracketIdx = fullName.indexOf("(");
String methodNameWithoutParam = fullName.substring(0, openBracketIdx);
String[] arrays = methodNameWithoutParam.split("\\.");
int length = arrays.length;
return arrays[length - 2] + "." + arrays[length - 1];
}
最后的“throws java.lang.Exception”有问题
在controller⾥⾯去掉update后的抛异常的部分,问题解决。
在此,明⽩了。拦截器⾥⾯的三个参数:
request : 是指经过spring封装的请求对象, 包含请求地址, 头, 参数, body(流)等信息.
respon:是指经过spring封装的响应对象, 包含输⼊流, 响应body类型等信息.
我的学习生活handler,是指controller的@Controller注解下的"完整"⽅法名, 是包含exception等字段信息的.

本文发布于:2023-06-14 16:14:25,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1038308.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:包含   请求   对象   报错   参数   内容   响应   信息
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图