# Mapper 설정
BoardMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sinc.intern.board">
...
<select id="read" parameterType="board" resultType="board">
SELECT SEQ, TITLE, CONTENT, WRITER, TO_CHAR(REGDATE, 'YYYY-MM-DD') AS REGDATE, VIEWCNT
FROM INTERN_BOARD_TBL
WHERE SEQ = #{seq}
</select>
</mapper>
# DAO 설정
package com.sinc.intern.board.model.sql;
import java.util.List;
public interface BoardDao {
public List<Object> listRow();
public int registerRow(Object obj);
public Object readRow(Object obj);
}
package com.sinc.intern.board.model.sql;
import java.util.List;
import javax.annotation.Resource;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;
@Repository("boardD")
public class BoardDaoImpl implements BoardDao {
// Session 생성
@Resource(name="sqlSession")
private SqlSession session;
public static final String PREFIX_B = "com.sinc.intern.board";
@Override
public List<Object> listRow() {
System.out.println("Board DAO List");
// selectList
List<Object> result = session.selectList(PREFIX_B +".list");
System.out.println("DAO Board Select result : " + result);
return result;
}
@Override
public int registerRow(Object obj) {
System.out.println("Board DAO Insert:" + obj);
// insert
return session.insert(PREFIX_B + ".register", obj);
}
@Override
public Object readRow(Object obj) {
System.out.println("Board Read SEQ : " + obj);
Object result = session.selectOne(PREFIX_B + ".read", obj);
System.out.println("Board Read result : " + result);
return result;
}
}
# Service 설정
package com.sinc.intern.board.service;
import java.util.List;
public interface BoardService {
public List<Object> list();
public int register(Object obj);
public Object read(Object obj);
}
package com.sinc.intern.board.service;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.sinc.intern.board.model.sql.BoardDao;
@Service("boardS")
public class BoardServiceImpl implements BoardService{
@Resource(name="boardD")
private BoardDao dao;
// Service에서 DAO 호출 후 메서드 수행
@Override
public List<Object> list() {
System.out.println("Board get list");
return dao.listRow();
}
@Override
public int register(Object obj) {
// TODO Auto-generated method stub
System.out.println("Board service insert data");
return dao.registerRow(obj);
}
@Override
public Object read(Object obj) {
System.out.println("Board service Read data");
return dao.readRow(obj);
}
}
# Ctrl 설정
package com.sinc.intern.board.ctrl;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.sinc.intern.board.model.vo.BoardVO;
import com.sinc.intern.board.service.BoardService;
@Controller
public class BoardCtrl {
@Resource(name="boardS")
private BoardService service;
...
// 글 가져오기
@RequestMapping("/readPage.do")
public String read(BoardVO obj, Model model) {
System.out.println("Board Read :" + obj);
Object board = service.read(obj);
model.addAttribute("board", board);
return "board/readPage";
}
}
# Front 설정
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="../include/header.jsp" %>
<!-- Main content -->
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">READ BOARD</h3>
</div><!-- /.box-header -->
<%--
<form role="form" action="modifyPage" method="post">
<input type='hidden' name='bno' value ="${boardVO.bno}">
<input type='hidden' name='page' value ="${cri.page}">
<input type='hidden' name='perPageNum' value ="${cri.perPageNum}">
</form>
--%>
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<input type="text" name='title' class="form-control"
value="${board.title}" readonly="readonly">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Content</label>
<textarea class="form-control" name="content" rows="3"
readonly="readonly">${board.content}</textarea>
</div>
<div class="form-group">
<label for="exampleInputEmail1" >Writer</label>
<input type="text" name="writer" class="form-control"
value="${board.writer}" readonly="readonly">
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<c:if test="${ loginUser.id == board.writer }">
<button id="modify" type="button" class="btn btn-warning">Modify</button>
<button id="remove" type="button" class="btn btn-danger">REMOVE</button>
</c:if>
<button id="list" type="button" class="btn btn-primary">GO LIST </button>
</div>
</div><!-- /.box -->
</div><!--/.col (left) -->
</div> <!-- /.row -->
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<%@include file="../include/footer.jsp" %>
'Archived(Programming) > Spring #1(기초)' 카테고리의 다른 글
Spring_data 처리5(글 수정) (0) | 2020.02.07 |
---|---|
Spring_data 처리4(글 삭제) (0) | 2020.02.07 |
Spring_data 처리2(글 작성) (0) | 2020.02.06 |
Spring_data 처리(글 목록) (0) | 2020.02.06 |
Spring_Mybatis 연동 (0) | 2020.02.04 |