기록해! 정리해!

JPAJarTymeleaf-1 상세보기, 삭제하기, 수정하기 본문

SpringBoot

JPAJarTymeleaf-1 상세보기, 삭제하기, 수정하기

zsuling 2022. 10. 18. 16:05
getBoardList 타이틀에 링크걸어서 상세보기 만들기

 

1. BoardService

2. BoardServiceImpl

package com.rubypaper.board;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BoardServiceImpl implements BoardService{

	@Autowired
	private BoardRepository boardRepo;
	
	@Override
	public void insert(Board vo) {
		boardRepo.save(vo);
	}

	@Override
	public List<Board> getBoardList() {

		return (List<Board>)boardRepo.findAll();
	}

	@Override
	public Optional<Board> getBoard(Long seq) {

		return boardRepo.findById(seq);
	}

}

3. BoardController

	@RequestMapping("/getBoard.do")
	public void getBoard(Model model, Board vo) {
		model.addAttribute("m", boardService.getBoard(vo.getSeq()).get());
	}

4. getBoard

<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 th:text="${m.seq}" /></tr>
<tr><td>TITLE</td>  <td th:text="${m.title}"/></tr>
<tr><td>WRITER</td>  <td th:text="${m.writer}" /></tr>
<tr><td>CONTENT</td>  <td th:text="${m.content}" /></tr>
<tr><td>PASSWORD</td>  <td th:text="${m.password}" /></tr>
<tr><td>DATE</td>  <td th:text="${m.createDate}" /></tr>
<tr><td>cnt</td>  <td th:text="${m.cnt}" /></tr>
</table>
</div>
</body>
</html>

 

5. getBoardList 타이틀에 링크걸기

 

<td><a th:href=@{getBoard.do(seq=${m.seq})}> [[${m.title}]] </a></td>

>>


getBoardList 작성자에 링크걸어서 삭제하기

1. BoardService

2. BoardServiceImpl

3. BoardController

4. getBoardList에 링크걸기

>>


상세보기에 수정하기 만들기

1. BoardService

2. BoardServiceImpl

3. BoardController

4. getBoard

<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>
<form action=update.do>
<table border=1>
<tr><td>SEQ</td> <td> <input type=text name=seq th:value="${m.seq}" /></td></tr>
<tr><td>TITLE</td> <td> <input type=text name=title th:value="${m.title}" /></td></tr>
<tr><td>WRITER</td>  <td> <input type=text name=writer th:value="${m.writer}" /></td></tr>
<tr><td>CONTENT</td>  <td> <input type=text name=content th:value="${m.content}" /></td></tr>
<tr><td>PASSWORD</td>  <td> <input type=text name=password th:value="${m.password}" /></td></tr>
<tr><td>DATE</td>  <td th:text="${m.createDate}" /></tr>
<tr><td>cnt</td>  <td th:text="${m.cnt}" /></tr>
<tr><td colspan=2 align=center><input type=submit th:value="수정하기"></td></tr>
</table>
</form>
</div>
</body>
</html>

>>

 

Comments