Q:
Is it possible to somehow get a hold of a @PathVariable in a @ControllerAdvice given that the PathVariable is only present in some requests?
If this was in a Controller, I could write 2 different Controllers. But a ControllerAdvice always applies to all requests. I can't have a ControllerAdvice apply to only Controllers where the PathVariable is defined.
A:
You can inject the Map of path variables and check for the existence of a key.
public void advise(@PathVariable Map<String, String> pathVariables) { if (pathVariables.containsKey("something")) { String something = pathVariables.get("something"); // do something } else { // do something else } }
相关推荐
获取Spring中@PathVariable注解里带点的完整参数.doc
@PathVariable和@RequestParam的区别
SpringMVC@RequestMapping(重点)@RequestParam@PathVariable示例
面试官:Spring 注解 @After,@Around,@Before 的执行顺序是?.zip 面试官:Spring 注解 @After,@Around,@Before 的执行顺序是?.zip 面试官:Spring 注解 @After,@Around,@Before 的执行顺序是?.zip 面试官:...
本文主要介绍了spring mvc中的@PathVariable获得请求url中的动态参数的代码。具有很好的参考价值,下面跟着小编一起来看下吧
NULL 博文链接:https://snowolf.iteye.com/blog/1628861
@JsonPropertyOrder , @JsonSerialize , @JsonSetter , @Lazy , @Order , @PathVariable , @Pointcut , @PostConstruct , @PostMapping , @PreDestroy , @Primary , @PropertySource , @Qualifier , @Repository , ...
spring 支持@RequestBody注解依赖包 、 spring 支持@RequestBody注解依赖包 spring 支持@RequestBody注解依赖包
2、配置步骤: 1)引入架包;... spring-webmvc-2.5.6.jar不支持@PathVariable注解,参数必须采用传统方式的?传递;3以上版本就支持@PathVariable注解,允许的话,建议采用SpringMVC4,增加了一些新特性 ;
springmvc2.5.6实现webservice 接口 带参数... spring-webmvc-2.5.6.jar不支持@PathVariable注解,参数必须采用传统方式的?传递;3以上版本就支持@PathVariable注解,允许的话,建议采用SpringMVC4,增加了一些新特性
spring事务管理注解jar,spring-tx-3.2.4.RELEASE.jar,导入项目即可
SpringAOP是什么?为什么要有SpringAOP?
2、配置步骤: 1)引入架包;... spring-webmvc-2.5.6.jar不支持@PathVariable注解,参数必须采用传统方式的?传递;3以上版本就支持@PathVariable注解,允许的话,建议采用SpringMVC4,增加了一些新特性 ;
Spring注解 @Component、@Repository、@Service、@Controller区别,有兴趣的可能看一下。
Spring注解@Component、@Repository、@Service、@Controller区别.doc
主要介绍了JAVA 中Spring的@Async用法总结的相关资料,需要的朋友可以参考下
spring boot @scheduled注解 cron 表达式实现计划任务调度。
SpringCloud中关于Feign的常见问题总结,包括常用的请求注解、@PathVariable、FeignClient多参数的构造等
Spring注解@Resource和@Autowired.doc