當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
[SpringBoot2]@MatrixVariableUrlPathHelper
生活随笔
收集整理的這篇文章主要介紹了
[SpringBoot2]@MatrixVariableUrlPathHelper
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
- 場景
頁面開發,cookie禁用了,session里面的內容怎么使用:
session.set(a,b)—>jessionid—>cookie—>每次發請求攜帶
此時cookie禁用了,我們要怎么得到session里面的內容呢?
url重寫:/abc;jsessionid=xxxx 把cookie的值使用矩陣變量的方式進行傳遞
- 1、語法: 請求路徑:/cars/sell;low=34;brand=byd,audi,yd
- 2、SpringBoot默認是禁用了矩陣變量的功能
- 手動開啟:原理。對于路徑的處理。UrlPathHelper進行解析。removeSemicolonContent(移除分號內容)支持矩陣變量的
- 3、矩陣變量必須有url路徑變量才能被解析
使用矩陣變量前要配置!
下面是兩種配置方式:
@Configuration(proxyBeanMethods = false) public class WebConfig implements WebMvcConfigurer {@Overridepublic void configurePathMatch(PathMatchConfigurer configurer) {UrlPathHelper urlPathHelper = new UrlPathHelper();//設置為不移除分號后面的內容。矩陣變量功能才可以生效urlPathHelper.setRemoveSemicolonContent(false);configurer.setUrlPathHelper(urlPathHelper);}} @Configuration(proxyBeanMethods = false) public class WebConfig implements WebMvcConfigurer {@Beanpublic WebMvcConfigurer webMvcConfigurer(){return new WebMvcConfigurer() {@Overridepublic void configurePathMatch(PathMatchConfigurer configurer) {UrlPathHelper urlPathHelper = new UrlPathHelper(); //設置為不移除分號后面的內容。矩陣變量功能才可以生效urlPathHelper.setRemoveSemicolonContent(false);configurer.setUrlPathHelper(urlPathHelper);}};}} //1、語法: 請求路徑:/cars/sell;low=34;brand=byd,audi,yd//2、SpringBoot默認是禁用了矩陣變量的功能// 手動開啟:原理。對于路徑的處理。UrlPathHelper進行解析。// removeSemicolonContent(移除分號內容)支持矩陣變量的//3、矩陣變量必須有url路徑變量才能被解析@GetMapping("/cars/{path}")public Map carsSell(@MatrixVariable("low") Integer low,@MatrixVariable("brand") List<String> brand,@PathVariable("path") String path){Map<String,Object> map = new HashMap<>();map.put("low",low);map.put("brand",brand);map.put("path",path);return map;} // /boss/1;age=20/2;age=10@GetMapping("/boss/{bossId}/{empId}")public Map boss(@MatrixVariable(value = "age",pathVar = "bossId") Integer bossAge,@MatrixVariable(value = "age",pathVar = "empId") Integer empAge){Map<String,Object> map = new HashMap<>();map.put("bossAge",bossAge);map.put("empAge",empAge);return map;}總結
以上是生活随笔為你收集整理的[SpringBoot2]@MatrixVariableUrlPathHelper的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网络小说如何打造非常惊艳的开篇如何写好小
- 下一篇: [SpringBoot2]Thymele