How to serialize ANY Object into a URI?

前端 未结 2 1637
长发绾君心
长发绾君心 2020-12-31 09:39

My basic question: is there anything built that already does this automatically (doesn\'t have to be part of a popular library/package)? The main things I\'m working with ar

2条回答
  •  余生分开走
    2020-12-31 10:22

    Lets we have c1.

    c1.setC1prop1("C1prop1");
    c1.setC1prop2("C1prop2");
    c1.setC1prop3("C1prop3");
    

    Converts c1 into URI

        UriComponentsBuilder.fromHttpUrl("http://test.com")
                .queryParams(new ObjectMapper().convertValue(c1, LinkedMultiValueMap.class))
                .build()
                .toUri());
    

    After we will have

        http://test.com?c1prop1=C1prop1&c1prop2=C1prop2&c1prop3=C1prop3
    

提交回复
热议问题