NOW OR NEVER

[Spring] Thymeleaf 본문

Back-End/JAVA

[Spring] Thymeleaf

LAURA 2022. 6. 23. 12:49
반응형

Thymeleaf

  • 공식사이트 : https://www.thymeleaf.org/
  • jsp를 대신하는 것이다
    • jsp에서는 controller에서 상태 유지한 것을 jstl 태그롸 표현식을 이용해서 출력
    • thymeleaf에서는 controller에서 상태 유지한 것을 thymeleaf를 이용해서 출력
  • thymeleaf에서 ajax
    • jquery 이용 등 원래 하던대로 하면 됨
    • javascript는 XmlHttpReset
    • jquery는 Ajax
  • 상태 유지 시킨 값을 태그에서 사용 가능
  • 타임리프로 작성할 html은 template 안에서 작성
  • html에 html 태그 안 xmlns:th = "타임리프url" 작성해야 타임리프 사용 가능
    • <html xmlns:th="http://www/thymeleaf.org" >
  • 타임리프로 작성한 html은 태그 안의 속성으로 th:속성 = "${상태유지한 값}" 으로 작성
    • text로 가져오기 : th:text = "${상태유지한 값}"
    • 반복문 -> th:each = "f:${상태유지한 값}" 랑 th:text="${f}" 하면 해당 값 반복
    • 주소 연결 -> th:href="@{/서비스이름}"
  • dependency : [https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf]

tips

  • static : 정적인 html
  • template: 상태유지하고 실행시킬 html
  • restful은 query string(ex)detailbook?bookid=10)이 아닌 URI방식(detailBook/b)으로 데이터를 전달하는 것을 권장
  • URI 방식
    • controller
      • GetMapping("/서비스이름/{변수이름}") : 전달하는 변수이름을 /{변수이름}으로 추가
      • controller 매개변수 앞에 @PathVariable 작성해줘야 함 
      • @GetMapping("/detailBook/{bookid}") public ModelAndView detailBook(@PathVariable int bookid, Model model) { ModelAndView mav = new ModelAndView("detailBook"); model.addAttribute("book",dao.getBook(bookid)); return mav; }
    • template - html
      • 태그 안에 th:href="@{'/서비스명/'+${변수이름}}" 작성
  • mimeMessageHelper : https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/mail/javamail/MimeMessageHelper.html

MimeMessageHelper (Spring Framework 5.3.21 API)

Constant indicating a multipart message with a single root multipart element of type "related". Texts, inline elements and attachements will all get added to that root element. This was the default behavior from Spring 1.1 up to 1.2 final. This is the "Mic

docs.spring.io

  • react, vue -> jquery 대신 사용할 수 있고 axios를 이용하여 ajax를 수행

'Back-End > JAVA' 카테고리의 다른 글

[JAVA] 기초 문법 및 요소  (0) 2022.11.04
[JAVA] 자바 특징 및 관련 용어  (0) 2022.11.04
[Spring] JqGrid / AOP  (0) 2022.06.22
[Spring] Jquery  (0) 2022.06.17
[Spring] Spring boot로 Spring project 생성  (0) 2022.06.02
Comments