Build URL in java

前端 未结 5 1476
故里飘歌
故里飘歌 2021-02-05 00:56

Trying to build http://IP:4567/foldername/1234?abc=xyz. I don\'t know much about it but I wrote below code from searching from google:

import java.n         


        
5条回答
  •  孤城傲影
    2021-02-05 01:11

    If using Spring Framework:

    UriComponentsBuilder.newInstance()
      .scheme(scheme)
      .host(host)
      .path(path)
      .build()
      .toUri()
      .toURL();
    

    A new UriComponentsBuilder class helps to create UriComponents instances by providing fine-grained control over all aspects of preparing a URI including construction, expansion from template variables, and encoding.

    Know more: https://www.baeldung.com/spring-uricomponentsbuilder

    JavaDoc: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/UriComponentsBuilder.html

提交回复
热议问题