[ Frontend ]/JSP_Thymeleaf

[Thymeleaf, html, bootstrap] 자주 사용하는 태그 모음

2023. 4. 22. 15:53
목차
  1. HTML 헤더
  2. <html>, <head>
  3. 전체 컨테이너
  4. row,  column
  5. < form >
  6. 게시판 <Table>
  7. <button> 단순 링크 버튼
  8. 수평선

HTML 헤더

<html>, <head>

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <link th:href="@{/css/bootstrap.min.css}"
          href="../css/bootstrap.min.css" rel="stylesheet">
    <style>
        .field-error {
            border-color: #dc3545;
            color: #dc3545;
        }
    </style>
</head>

 

타임리프 사용 설정 - xmlns:th="http://www.thymeleaf.org" 
부트스트랩 css파일 상대경로 - th:href="@{/css/bootstrap.min.css}"
<style> 태그 : 오류발생시 사용

전체 컨테이너

<div class="container" style="max-width: 1000px">

<!-- code -->

</div>
컨테이너 좌우 너비 최대 1000px로 고정

row,  column

row 지정 후 그 row 안을 두개의 column으로 지정
왼쪽부터 첫번째 column은 text-start로, 두번째 column은 text-end 로 지정

<div class="py-1 row">
	<div class="col text-start">
		<!-- column 1 내용 -->
	</div>

	<div class="col text-end">
		<!-- column 2 내용 -->
	</div>
</div>

 

text-start / text-end / text-center :  해당 태그 내에 들어갈 요소의 위치 지정
py-1 : 해당 태그위 위 아래 여백설정

< form >

form의 <input> 에 작성한 내용을 아래에 type="submit"을 누르면 POST형식으로 제출한다.
그럼 해당 URL의 @PostMapping 된 메소드로 작성한 내용이 전달된다.

<form action="memberPage.html" th:action th:object="${form}" method="post" >
	<div>
	   <label for="currentPassword" th:text="#{label.member.currentPassword}">현재 비밀번호</label>
	   <input type="password" id="currentPassword" th:field="*{currentPassword}" 
	   	class="form-control" th:errorclass="field-error" >
	   <div class="field-error" th:errors="*{currentPassword}" />
	</div>
    
    <!-- 생략 -->
	
	<button class="w-100 btn btn-outline-danger btn-sm" th:text="#{button.editPassword}" type="submit">
		비밀번호 변경
	</button>
</form>

 

해당 URL의 @GetMapping된 컨트롤러에서 model.addAttribute("form", new EditMemberForm() ); 으로 빈 객체라도 전달해야한다.
th:object=${form}
는 컨트롤러로부터 "form"이란 이름의 객체를 받아서, 그 객체의 필드를 th:field=" *{...}" 로 받아서 매핑한다.
그럼 @PostMapping 된 컨트롤러에서 [ @Validated @ModelAttribute("form") EditMemberForm form ]  매개변수로 받아서 사용할 수 있다.

게시판 <Table>

<table class="table">
	<thead>
		<tr>
		   <th style="width: 100px; text-align: center" th:text="#{label.board.id}">번호</th>
		   <th style="width: 500px; text-align: center" th:text="#{label.board.title}">제목</th>
		   <th style="width: 150px; text-align: center" th:text="#{label.board.writer}">작성자</th>
		   <th style="width: 150px; text-align: center" th:text="#{label.board.date}">등록일</th>
		   <th style="width: 100px; text-align: center" th:text="#{label.board.views}">조회수</th>
		</tr>
	</thead>
    
	<tbody>
		<tr th:each="post : ${posts}">
		   <td style="width: 100px; text-align: center" th:text="${post.id}">1234</td>
		   <td style="width: 500px; text-align: center">
				<a th:href="@{/board/post/{postId}(postId=${post.id})}">
				<th:block th:text="${#strings.length(post.title) &gt; 20 ? #strings.substring(post.title, 0, 20) + '...' : post.title}">
				title-example
				</th:block>
				</a><!-- 문자열 길이가 20 넘어가면 ...으로 표시-->
			</td>
			<td style="width: 150px; text-align: center" th:text="${post.writerId}">hsryuuu</td>
			<td style="width: 150px; text-align: center" th:text="${post.create_date.plusDays(1) &lt; #temporals.createNow() ? #temporals.format(post.create_date, 'yyyy-MM-dd') : #temporals.format(post.create_date, 'HH:mm')}">
                    <!-- create_date가 현재시간으로부터 하루 이전이면 날짜를, 하루 이내면 시간을 표시 -->
			</td>
			<td style="width: 100px; text-align: center" th:text="${post.views}">23</td>
            </tr>
	</tbody>
</table>

<button> 단순 링크 버튼

<button class="btn-sm btn-primary py-1 "
	onclick="location.href='writeForm.html'"
	th:onclick="|location.href='@{/board/write-form}'|"
	th:text="#{button.writing}"
	type="button">글쓰기</button>
th:onclick에서 지정된 url을 Get 방식으로 호출한다.

수평선

<hr class="my-1">
<hr class="py-1">
my : 수평선 상하 여백 설정
py : 수평선 두께 설정

 

 

 

'[ Frontend ] > JSP_Thymeleaf' 카테고리의 다른 글

[JSP] JSP 간단 정리  (0) 2023.08.01
[Thymeleaf] 기본 문법 (연산, 반복, if, 블록)  (0) 2023.05.04
[Thymeleaf] 기본객체, 유틸리티 객체  (0) 2023.04.21
[Thymeleaf] 기본 문법 (text, 변수표현, URL 링크, 리터럴)  (0) 2023.04.20
[Thymeleaf] 타임리프 란?  (0) 2023.04.20
  1. HTML 헤더
  2. <html>, <head>
  3. 전체 컨테이너
  4. row,  column
  5. < form >
  6. 게시판 <Table>
  7. <button> 단순 링크 버튼
  8. 수평선
'[ Frontend ]/JSP_Thymeleaf' 카테고리의 다른 글
  • [JSP] JSP 간단 정리
  • [Thymeleaf] 기본 문법 (연산, 반복, if, 블록)
  • [Thymeleaf] 기본객체, 유틸리티 객체
  • [Thymeleaf] 기본 문법 (text, 변수표현, URL 링크, 리터럴)
HSRyuuu
HSRyuuu
Web Backend Developer happyhsryu
HSRyuuu
HS_dev_log
HSRyuuu
전체
오늘
어제
  • 전체 글 보기 (235)
    • Java (25)
    • Spring (29)
    • JPA & QueryDSL (13)
    • Database (17)
    • 자료구조 & 알고리즘 (30)
    • DevOps (10)
    • [ Computer Science ] (47)
      • Web & Network (14)
      • 프로그래밍 이론 (11)
      • 운영체제 (3)
      • 데이터베이스 이론 (5)
      • Linux 리눅스 (7)
    • [ Frontend ] (17)
      • Vue.js & Nuxt.js (9)
      • JSP_Thymeleaf (7)
    • [ 기타 ] (47)
      • 오픈소스 라이브러리 (5)
      • 코딩테스트 (13)
      • Trouble Shooting (7)
      • Tech Interview (6)
      • Book Review (9)
      • 끄적끄적... (5)
      • 개인 프로젝트 (2)

블로그 메뉴

  • 홈
  • 태그
  • github

공지사항

  • GitHub
  • 공부한 내용을 정리하고 기록하는 블로그 입니다.

인기 글

태그

  • MySQL
  • 제로베이스
  • 백엔드
  • web
  • 백엔드기술면접
  • 개발자
  • Database
  • SQL
  • HTTP
  • mybatis
  • 클린코드
  • 백엔드공부
  • Redis
  • JPA
  • Java
  • Linux
  • SpringBoot
  • springsecurity
  • TechInterview
  • Spring
  • 백준
  • 기술면접
  • 자료구조
  • 트랜잭션
  • vue3
  • 백엔드스쿨
  • Nuxt3
  • 리눅스
  • cleancode
  • Redisson

최근 댓글

최근 글

hELLO · Designed By 정상우.
HSRyuuu
[Thymeleaf, html, bootstrap] 자주 사용하는 태그 모음
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.