一、介绍
当Cookie被禁用时,可用矩阵变量做替代品。
二、使用
请求方式/user/1;age=20/zhangsan;weight=55
(1)先开启分号后的内容有效
@Configuration(proxyBeanMethods = false)
public class MyWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
UrlPathHelper urlPathHelper = new UrlPathHelper();
urlPathHelper.setRemoveSemicolonContent(false);
configurer.setUrlPathHelper(urlPathHelper);
}
}
(2)矩阵变量要写在路径变量中
@GetMapping("/user/{id}/{name}")
@ResponseBody
public String getUser(@PathVariable("id") Long id,
@PathVariable("name") String name,
@MatrixVariable("age") Long age,
@MatrixVariable("weight") Long weight){
return id + " " + name + " " + age + " " + weight;
}