[개발] th:href
                
                    필기자                
                                                
            
            
                                2022-10-19 11:29
                                10,657
                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

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¶m2=파라미터%20데이터2

                                                
                                        
                                
댓글목록0