목록에서 글 작성 눌렀을 경우
▶ 글 작성 폼 페이지로 단순 화면 이동만 하면 됨
▶ web.xml
>> 특정 코드로 끝나는 url 호출이 있을 경우
>> servlet-name에 지정되어 있는 이름의 servlet 을 호출 하겠다
>> servlet-context
▶ servlet-context
>> 파일을 알아서 찾아줌
>> annotation-driven
>> componet-scan : 특정 패키지 내의 클래스를 스캔하고 Annotation을 확인한 후 Bean 인스턴스로 생성한다.
>> @Controller 안에 어노테이션("insertBoard.do")을 찾음
Controller
▶ 방법 1
▶ 방법 2
▶ 방법 3 << 추천함
insertBoard.jsp
<h1>글 등록</h1>
<hr>
<form action="saveBoard.do" method="post"> <!-- enctype="multipart/form-data" -->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="orange" width="70">제목</td>
<td align="left"><input type="text" name="title" /></td>
</tr>
<tr>
<td bgcolor="orange">작성자</td>
<td align="left"><input type="text" name="writer" size="10" /></td>
</tr>
<tr>
<td bgcolor="orange">내용</td>
<td align="left"><textarea name="content" cols="40" rows="10"></textarea></td>
</tr>
<!-- <tr> -->
<!-- <td bgcolor="orange" width="70">업로드</td><td align="left"> -->
<!-- <input type="file" name="uploadFile"/></td> -->
<!-- </tr> -->
<tr>
<td colspan="2" align="center"><input type="submit" value=" 새글 등록 " /></td>
</tr>
</table>
</form>
<hr>
<a href="getBoardList.do">글 목록 가기</a>
새 글 등록 버튼 눌렀을 경우
▶ <form action="saveBoard.do" method="post">
>> 특정 url 입력 >> web.xml / servlet-context.xml >> Controller 찾음
▶ <input type="submit" value=" 새글 등록 " />
▶ 데이터를 BoardVO 로 받아옴 >> 태그의 name 속성과 BoardVO의 변수명이 동일 해야함
▶ 새 글 등록 후 목록 페이지로 화면 전환되게 하자
BoardVO
▶ getter / setter 도 있음
▶ 태그의 name 속성과 BoardVO의 변수명이 동일 해야함
Controller
▶ 단순 return 하면 안되고 게시글 목록을 불러와야함
>> 이미 만들어 놓은거 있음 getBoardList()
>> return "redirect:/getBoardList.do";
BoardService
BoardDAO
Mapper
▶ mybatis-config.xml >> BoardDAO의 alias="board" 되어있음
▶ parameterType="별칭"
'Programming > Java + Spring' 카테고리의 다른 글
[Spring] 게시판 만들기 / 글 수정, 글 삭제 (0) | 2022.09.28 |
---|---|
[Spring] 게시판 만들기 / 글 보기 (0) | 2022.09.27 |
[Spring] 게시판 만들기 / 글 목록 가기 (0) | 2022.09.27 |
[Spring] 게시판 실습 / 준비 단계 (0) | 2022.09.27 |
[Spring] DI 실습 (0) | 2022.09.26 |
댓글