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 | 29 | 30 |
Tags
- MVC CRUD
- service
- 환경설정
- update
- Connection pool
- 게시판만들기
- delete
- 게시판 List
- MVC
- hikaricp
- Controller
- log4j
- spring
- CRUD
- MVC 게시판
- jdbc
- MVC설정
- log4jdbc
- Oracle 연결
- 서비스계층
- Oracle
- 게시판
- mybatis
Archives
- Today
- Total
yahayaha
12. 조회 처리하기. 본문
커뮤니티를 하거나 카페 블로그를 할 때 보통 게시글을 볼 때는 게시글의 타이틀 즉 제목을 보고 클릭함.
그럼 우리는 조회를 하려면 그 타이틀을 클릭했을때 GET요청을 보내서 조회를 할 수 있도록 해야함.
그 작업을 진행.
컨트롤러는 따로 만들지는 않았지만
mapper는 테스트 코드를 통해서 대강 만들었음.
서비스 쪽도 Get이라는 기능을 미리 작성을 함.
진행 순서는 이렇게 됨.
1. Service에서 get이라는 기능을 실행
2. mapper에서 데이터를 가져옴.
3. BoardVO 객체를 전달해주면 컨트롤러에서 전달을 해줘야함
4. 이떄 필요한게 model addattribute 조회를 할때는 게시물의 번호만 조회함.
5. 화면에 전달 할 때는 boardVO 객체를 가져와서 전달해줘야함.
그럼 작업을 해봅시다.
먼저 컨트롤러에 추가 코드 작성.
@GetMapping("/get")
public void get(@RequestParam("bno")long bno, Model model) {
model.addAttribute("board", service.get(bno));
}
bno를 수집한다고 명시적으로 하기위해 @RequestParam을 사용.
DB를 통해서 새로운 데이터가 추가되서 나가야 하기 때문에 Model 사용.
Model에 객체를 담기위해 addAttribute를 사용.
service에서 get(bno)를 모델에 전달.
화면을 작업하기 위해 get.jsp를 생성.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@include file="../includes/header.jsp" %>
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Board Read</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Board Read
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="form-group">
<label>BNO</label>
<input class="form-control" name="bno" readonly="readonly" value='<c:out value="${board.bno}"/>'>
</div>
<div class="form-group">
<label>Title</label>
<input class="form-control" name="title" readonly="readonly" value='<c:out value="${board.title}"/>'>
</div>
<div class="form-group">
<label>content</label>
<textarea class="form-control" name="content" rows="5"><c:out value="${board.content}"/></textarea>
</div>
<div class="form-group">
<label>Writer</label>
<input class="form-control" name="writer" value='<c:out value="${board.writer}"/>'>
</div>
<div class="dox-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
<%@include file="../includes/footer.jsp" %>
톰캣 실행 후 제대로 동작이 되는지 확인
이제 list.jsp에 a태그를 달아서 get으로 가는 링크를 만드는 작업을 함.
<td><a href='/board/get?bno=<c:out value="${board.bno}"/>'><c:out value="${board.title}"/></td>
그리고 다시 board/list로 가서 확인.
링크가 생긴걸 확인 가능함.
뒤로가기 문제에 관해서는 정리 후 따로 포스팅 예정.
'spring > 프로젝트' 카테고리의 다른 글
14. MyBatis로 Spring페이징 처리하기. (1) | 2024.01.27 |
---|---|
13. 게시물 수정과 삭제. (0) | 2024.01.27 |
11. 목록 화면에 처리하고 등록하기 (JSTL) (2) | 2024.01.24 |
10. 프레젠테이션(웹) CRUD 구현 ( 삭제 / 수정) (0) | 2024.01.23 |
9. 프레젠테이션(웹) CRUD 구현 (0) | 2024.01.23 |