/**
* 文章详情
*
* @param id 文章ID
*/
@GetMapping("/detail/{id}")
public R<ArticleVo> detail(@PathVariable("id") Long id) {
return R.ok(articleService.detail(id));
}
可以看到以上我的代码,需要一个Long类型的id
如果参数类型不对,要怎么拦截呢?
方法来了,如下!
/**
* 接口方法参数类型异常
*/
@ExceptionHandler(value = MethodArgumentTypeMismatchException.class)
@ResponseBody
public Object methodArgumentTypeMismatchException(Throwable e) {
log.error("url参数异常,请检查参数类型是否匹配!", e);
return R.error("请检查参数类型是否正确");
}
发表评论- Comments
您必须登录或注册发表评论
Limitless
IP属地:广东省
作者网站真漂亮,简洁美观!

