💻 it/development

[thyemeleaf] get query string parameter

꼬비랩 2026. 1. 11.
 

thyemeleaf에서 url의 query string 사용

미래에 이 내용을 잊었을 내가 보기 위해 기록함

위 사진에서처럼 url이 http://localhost:8080/tables/detail?tableName=tb_menu 일 경우 

다른 페이지 이동 시 query string parameter를 가져와서 get으로 넘기고 싶을 땐

아래처럼 사용하면 된다.

<a th:href="@{/tables/addField(tableName=${param.tableName})}" id="addField" class="btn btn-primary">필드추가</a>

${param.parameter} 이 부분이다.

여러개를 넘기고 싶을 땐 아래처럼 하면 된다.

${param.fields[index]}

<a th:href="@{/tables/test1(tableName=${param.fields[0]})}">test1</a>
<a th:href="@{/tables/test2(tableName=${param.fields[1]})}">test2</a>
<a th:href="@{/tables/test3(tableName=${param.fields[2]})}">test3</a>

 

그러면 아래처럼 필드추가 페이지 이동 시 쿼리스트링이 전달됨을 확인 할 수 있다.

 

Reference: https://attacomsian.com/blog/thymeleaf-get-query-string-parameters

 

How to get query string parameters in Thymeleaf

A quick article to learn how to get query string parameters in Thymeleaf templates.

attacomsian.com

     

    댓글