◽ Java language/Java

[Java - (5) ] UriComponents - URI 쉽게 만들기

UriComponents

서버단에서 쉽게 URI만들어주는 클래스.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    public void testURI() throws Exception{
        
        UriComponents uriComponents = UriComponentsBuilder.newInstance()
                .path("/samplehome/board/read")
                .queryParam("bno"12)
                .queryParam("perPageNum"20)
                .build();
        
        logger.info("/samplehome/board/read?bno=12&perPageNum=20");
        logger.info(uriComponents.toString());  // /samplehome/board/read?bno=12&perPageNum=20 가 생성된다.
    }
    
    public void testURI2() throws Exception{
        UriComponents uriComponents = UriComponentsBuilder.newInstance()
                .path("/{a}/{b}/{c}")
                .queryParam("bno"12)
                .queryParam("perPageNum"20)
                .build()
                .expand("samplehome""board""read")
                .encode();
        
        logger.info("/samplehome/board/read?bno=12&perPageNum=20");  
        logger.info(uriComponents.toString()); // /samplehome/board/read?bno=12&perPageNum=20 가 생성된다.
    }
Color Scripter
 

푸터바