th:href > 스프링 부트

본문 바로가기

[개발] th:href

필기자
2022-10-19 11:29 2,745 0

본문

kr/ac/gachon/shop/controller/ThymeleafExController.java 내용 추가



@Controller
@RequestMapping(value="/thymeleaf")
public class ThymeleafExController {
    .
    .
    .
    @GetMapping(value = "/ex05")
    public String thymeleafExample05(){
        return "thymeleafEx/thymeleafEx05";
    }
}

 

templates/thymeleafEx/thymeleafEx05.html 파일 생성 및 작성



<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
   <head>
      <meta charset="UTF-8">
      <title>Title</title>
   </head>
   <body>
      <h1>Thymeleaf 링크처리 예제 페이지</h1>
      <div>
         <a th:href="@{/thymeleaf/ex01}">예제1 페이지 이동</a>
      </div>
      <div>
         <a th:href="@{https://www.thymeleaf.org/}">thymeleaf 공식 페이지 이동</a>
      </div>
      <div>
         <a th:href="@{/thymeleaf/ex06(param1 = '파라미터 데이터1', param2 = '파라미터 데이터2')}">thymeleaf 파라미터 전달</a>
      </div>
   </body>
</html>

 

결과 http://localhost:8080/thymeleaf/ex05

 

20221101134938_58c21c62e2e6f71b42558e4bc6ecc1e2_1awo.png

 

thymeleaf 파라미터 전달 처리

 

kr/ac/gachon/shop/controller/ThymeleafExController.java 내용 추가



@Controller
@RequestMapping(value="/thymeleaf")
public class ThymeleafExController {
    .
    .
    .
    @GetMapping(value = "/ex06")
    public String thymeleafExample06(String param1, String param2, Model model){
        model.addAttribute("param1", param1);
        model.addAttribute("param2", param2);
        return "thymeleafEx/thymeleafEx06";
    }
}

 

 

templates/thymeleafEx/thymeleafEx06.html 파일 생성 및 작성



<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>
  <body>
    <h1>파라미터 전달 예제</h1>
    <div th:text="${param1}"></div>
    <div th:text="${param2}"></div>
  </body>
</html>

 

thymeleaf 파라미터 전달 처리 결과

http://localhost:8080/thymeleaf/ex05 > thymeleaf 파라미터 전달 클릭

http://localhost:8080/thymeleaf/ex06?param1=파라미터%20데이터1&param2=파라미터%20데이터2

 

20221101134914_58c21c62e2e6f71b42558e4bc6ecc1e2_2flw.png

 

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색