Spring 解析(获取)URL 参数

import org.springframework.web.util.UriComponentsBuilder;

public static void main(String[] args) {
    String uri = "http://my.test.com/test?param1=ab&param2=cd&param2=ef";
    MultiValueMap<String, String> parameters =
            UriComponentsBuilder.fromUriString(uri).build().getQueryParams();
    List<String> param1 = parameters.get("param1");
    List<String> param2 = parameters.get("param2");
   String firstParam1 = parameters.getFirst("param1");
    System.out.println("firstParam1: " + firstParam1 );
    System.out.println("param1: " + param1.get(0));
    System.out.println("param2: " + param2.get(0) + "," + param2.get(1)); 
}

 

posted @ 2021-04-26 15:09  为牛马者,背负前行  阅读(772)  评论(0编辑  收藏  举报

如果本页面列出的内容侵犯了您的权益,请告知。
知识共享许可协议
996.icu