Build URL in java

前端 未结 5 1493
故里飘歌
故里飘歌 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:15

    If you happen to be using Spring already, I have found the org.springframework.web.util.UriComponentsBuilder to be quite nifty. Here is how you would use it in your case.

    final URL myUrl = UriComponentsBuilder
            .fromHttpUrl("http://IP:4567/foldername/1234?abc=xyz")
            .build()
            .toUri()
            .toURL();
    

提交回复
热议问题