Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 스프링 시큐리티
- 페이징
- 처음 만나는 AI 수학 with Python
- /etc/network/interfaces
- 자료구조와함께배우는알고리즘입문
- d
- 자료구조와 함께 배우는 알고리즘 입문
- 친절한SQL튜닝
- 스프링부트핵심가이드
- 코드로배우는스프링웹프로젝트
- 선형대수
- Kernighan의 C언어 프로그래밍
- baeldung
- 처음 만나는 AI수학 with Python
- 데비안
- 이터레이터
- 알파회계
- 리눅스
- 목록처리
- network configuration
- resttemplate
- 구멍가게코딩단
- GIT
- ㅒ
- 서버설정
- 네트워크 설정
- iterator
- 자바편
- 코드로배우는스프링부트웹프로젝트
- 티스토리 쿠키 삭제
Archives
- Today
- Total
bright jazz music
[bootBoard] N:1(다대일) 연관관계: 10-2 화면처리: 게시물 등록 처리 본문
Framework/Spring
[bootBoard] N:1(다대일) 연관관계: 10-2 화면처리: 게시물 등록 처리
bright jazz music 2022. 10. 9. 21:44게시물 등록 처리
1. BoardController에 등록을 위한 코드 추가
//BoardController.java
@Controller
@RequestMapping("/board/")
@Log4j2
@RequiredArgsConstructor
public class BoardController {
private final BoardService boardService;
...
//등록(get) : 등록을 위한 페이지 반환
@GetMapping("/register")
public void register(){
log.info("register get...");
}
//등록(post) : 등록을 위한 페이지에 입력된 값을 BoardDTO로 받아서 처리
@PostMapping("/register")
public String registerPost(BoardDTO dto, RedirectAttributes redirectAttributes){
log.info("dto..." + dto);
//새로 추가된 엔티티의 번호
Long bno = boardService.register(dto);
log.info("BNO: " + bno);
redirectAttributes.addFlashAttribute("msg", bno);
return "redirect:/board/list";
}
...
}
2. 등록을 위한 페이지 생성 register.html
register.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<th:block th:replace="~{/layout/basic :: setContent(~{this::content})}">
<th:block th:fragment="content">
<h1 class="mt-4">Board Register Page</h1>
<!--버튼 클릭 시 /board/register로 POST 발사!!! -->
<form th:action="@{/board/register}" th:method="post">
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" name="title" placeholder="Enter Title">
</div>
<div class="form-group">
<label>Content</label>
<textarea class="form-control" rows="5" name="content"></textarea>
</div>
<div class="form-group">
<label>Writer Email</label>
<input type="email" class="form-control" name="writerEmail" placeholder="Writer Email">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</th:block>
</th:block>
2. 폼에 값 입력 뒤 submit 버튼 클릭
- 단, 이 때 Writer Email 필드의 값은 반드시 member 테이블에 존재하는 값을 넣어줘야 함.
- 여기서는 user100@aaa.com을 예시로 사용했음.
- member테이블에 존재하지 않는 값을 입력하면 에러 발생.
3. 목록 확인
콘솔로그
2022-10-09 21:48:42.140 INFO 8052 --- [nio-8080-exec-3] c.e.b.controller.BoardController : dto...BoardDTO(bno=null, title=등록 테스트 title, content=등록 테스트 content, writerEmail=user100@aaa.com, writerName=null, regDate=null, modDate=null, replyCount=0)
2022-10-09 21:48:42.140 INFO 8052 --- [nio-8080-exec-3] c.e.bootboard.service.BoardServiceImpl : BoardDTO(bno=null, title=등록 테스트 title, content=등록 테스트 content, writerEmail=user100@aaa.com, writerName=null, regDate=null, modDate=null, replyCount=0)
Hibernate:
select
member_.email,
member_.moddate as moddate2_1_,
member_.name as name4_1_,
member_.password as password5_1_
from
member member_
where
member_.email=?
Hibernate:
insert
into
board
(moddate, reg_date, content, title, writer_email)
values
(?, ?, ?, ?, ?)
'Framework > Spring' 카테고리의 다른 글
[bootBoard] N:1(다대일) 연관관계: 10-4 화면처리: 게시물 수정/삭제 처리 (0) | 2022.10.09 |
---|---|
[bootBoard] N:1(다대일) 연관관계: 10-3 화면처리: 게시물 조회 처리 (0) | 2022.10.09 |
[bootBoard] N:1(다대일) 연관관계: 10-1 화면처리: 목록, 페이징 (0) | 2022.10.08 |
[bootBoard] N:1(다대일) 연관관계: 9-5. 프로젝트 적용: 게시물 수정 처리 (0) | 2022.10.08 |
[bootBoard] N:1(다대일) 연관관계: 9-4. 프로젝트 적용: 게시물 삭제 처리 (0) | 2022.10.07 |
Comments