250x250
Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags more
Archives
Today
Total
관리 메뉴

개린이 개발노트

국비지원 JAVA(자바) 프로그래밍 (타임리프 이용) 본문

국비지원(국비교육) 웹 개발자 과정

국비지원 JAVA(자바) 프로그래밍 (타임리프 이용)

개린이9999 2023. 2. 14. 09:48
728x90

thymeleaf 

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf

 

//thymeleaf
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	// layout thymeleaf
	implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'

그래들에 추가 완료 

 

 

<tr th:each="quesiton : ${questionList}"> 

-> 타임리프 문법 

 

package com.example.sb.question;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Controller
public class QuestionController {
   
   private final QuestionRepository questionRepository;
   
   @GetMapping("/question/list")
   public String list(Model model) { //model은 자바스크립트로 따지면 이벤트같은 기능, request역할을 해줌
      //질문 목록을 뽑아내는 코드
      List<Question> questionList = questionRepository.findAll();
      model.addAttribute("questionList", questionList);
      
      return "question_list";
   }

}
<table>   
   <tr>
      <th>제목</th>
      <th>작성일</th>
   </tr>
   <tr th:each="question : ${questionList}">
      <td th:text="${question.subject}"></td>
      <td th:text="${question.createDate}"></td>
   </tr>
</table>

질문에 해당하는 답변을 등록

 

Answer 테이블에 레코드를 추가

id : 레코드를 식별하는 필드 (답변코드 같은개념)

content : 답변에 해당하는 내용

createDate : 답변 작성일 

quesiton : 질문 객체(질문에 해당하는 모든정보)

728x90