기록해! 정리해!

JPAJarTymeleaf-1 UI (getBoardList, form) 본문

SpringBoot

JPAJarTymeleaf-1 UI (getBoardList, form)

zsuling 2022. 10. 18. 13:08

 

1. index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<h2> JPA 시작하기 </h2>
<a href=getBoardList.do>목록보기</a> <br><br>
<a href=form.do>저장하기</a> <br><br>
</body>
</html>

2. getBoardList.html

<html xmlns:th="http://www.thymeleaaf.org">
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<br>
<h2> 목록보기 <a href=index.html>(처음으로)</a></h2>
<table border=1>
<tr>
<td>SEQ</td>
<td>TITLE</td>
<td>WRITER</td>
<td>cnt</td>
</tr>

<tr align="center" th:each="m : ${li}"> 
 <td th:text="${m.seq}" />
 <td th:text="${m.title}" />
 <td th:text="${m.writer}" />
 <td th:text="${m.cnt}" />
 </tr>
 
</table>
</div>
</body>
</html>

3. BoardController

package com.rubypaper.board;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class BoardController {

	@Autowired 
	BoardServiceImpl boardService;
	
	@RequestMapping("/form.do")
	public void form() {
		
	}
	
	@RequestMapping("/formOk.do")
	public String formOk(Board vo) {
		boardService.insert(vo);
		return "redirect:getBoardList.do";
	}
	
	@RequestMapping("/getBoardList.do")
	public void getBoardList(Model model) {
		model.addAttribute("li", boardService.getBoardList());
	}

}

>>

>>


form (저장하기)

 

1. form.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<h2>form</h2>
<form action="formOk.do">
<table border=1 >
<tr> <td > 제목 </td><td > <input type=text name=title>  </td> </tr>
<tr> <td> 작성자 </td> <td > <input type=text name=writer></td> </tr>
<tr> <td> 내용 </td><td > <input type=text  name=content  >  </td> </tr>
<tr> <td> 암호 </td> <td > <input type=text name=password  >  </td> </tr>
<tr> <td colspan=2  align="center"> <input type=submit value="저장하기" >
     </td> 
</tr>

</table>
</form>
</body>
</html>

>>

Comments