-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUrlBuilderTest.java
More file actions
50 lines (38 loc) · 1.85 KB
/
UrlBuilderTest.java
File metadata and controls
50 lines (38 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package kr.co.freeism;
import static org.junit.Assert.*;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.junit.Test;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import com.google.common.collect.Lists;
/**
* @author freeism
* @since 15. 4. 23 오전 11:47
* @see http://www.leveluplunch.com/java/examples/build-convert-map-to-query-string/
*/
public class UrlBuilderTest {
@Test
public void test() throws Exception {
UriComponents components = UriComponentsBuilder.fromUriString("http://www.freeism.co.kr/test?id=1000").query("name=freeism").build();
System.out.println(components.toUriString());
UriComponents components2 = UriComponentsBuilder.fromUriString("http://www.freeism.co.kr/test").query("name=freeism").build();
System.out.println(components2.toUriString());
UriComponents components3 = UriComponentsBuilder.fromUriString("http://www.freeism.co.kr/test?id=1000").query(
"name=freeism&email=freeism@freeism.co.kr").build();
System.out.println(components3.toUriString());
List<NameValuePair> list = Lists.newArrayList();
list.add(new BasicNameValuePair("name", "freeism"));
URIBuilder builder = new URIBuilder("http://www.freeism.co.kr/test?id=1000").addParameters(list);
System.out.println(builder.build());
URIBuilder builder2 = new URIBuilder("http://www.freeism.co.kr/test").addParameters(list);
System.out.println(builder2.build());
list.add(new BasicNameValuePair("email", "freeism@freeism.co.kr"));
URIBuilder builder3 = new URIBuilder("http://www.freeism.co.kr/test?id=1000").addParameters(list);
System.out.println(builder3.build());
}
}