본문 바로가기

Web/Spring

Spring 게시판 만들기~

 ★ 핵심만 정리 했습니다.


list.jsp


<!-- 글목록시작-->

<c:forEach var="item" items="${list }" varStatus="status">

<c:if test="${status.count%2 == 0 }">

<tr align="center">

</c:if>

<c:if test="${status.count%2 == 1 }">

<tr align="center" style="background-color: white">

</c:if>

 

<td>${item.no }</td>

<td><a href="<%=cp%>/bd/read?no=${item.no}

&amp;page=${page}

&amp;key=${param.key}

&amp;value=${param.value}" style="text-decoration: none">${item.title }</a></td>

<td>${item.writer }</td>

<td>${item.wdate }</td>

<td>${item.rcount }</td>

</tr>

</c:forEach>

 

<td colspan="5" style="text-align: center">

<c:if test="${firstPage != 1 }">

<a href="<%=cp%>/bd/list?page=${firstPage-1}&amp;key=${param.key}&amp;value=${param.value}" style="text-decoration: none">[이전]</a>

</c:if>

<c:forEach var="i" begin="${firstPage}" end="${lastPage }">

<c:if test="${page == i }"> <strong>${i }</strong>

</c:if>

<c:if test="${page ne i }">

<a href="<%=cp%>/bd/list?page=${i}&amp;key=${param.key}&amp;value=${param.value}" style="text-decoration: none">${i }</a>

</c:if>

</c:forEach>

<c:if test="${lastPage != totPage }">

<a href="<%=cp%>/bd/list?page=${lastPage+1}&amp;key=${param.key}&amp;value=${param.value}" style="text-decoration: none">[다음]</a>

</c:if>

<td colspan="5" style="text-align: right">

<input type="button" value="글쓰기"

onclick="location.href='<c:url value="/bd/write" />';"/>

 


read.jsp


function doDelete() {

location.href = '<%=cp%>/bd/delete{list.no}';

}

function doList() {

location.href = '<%=cp%>/bd/listpage=${param.page}&key=${param.key}&value=${param.value}';

}

function doUpdate() {

location.href = '<%=cp%>/bd/preupdateno=${list.no}&page=${param.page}';

}

 

<div class="title">글번호: ${list.no }</div>

<div class="title">글쓴이: ${list.writer }</div>

<div class="title">작성일: ${list.wdate }</div>

<div class="title">조회수: ${list.rcount }</div>

 

<input type="button" value="수&nbsp;&nbsp;&nbsp;정" class="bt" onclick="doUpdate();" />

<input type="button" value="삭&nbsp;&nbsp;&nbsp;제" class="bt" onclick="doDelete();" />

<input type="button" value="목&nbsp;&nbsp;&nbsp;록" class="bt" onclick="doList();" />

 


update.jsp


<c:if test="${empty item }">

<form action="<%=cp%>/bd/write" method="post">

</c:if>

<c:if test="${not empty item }">

<form action="<%=cp%>/bd/update?page=${param.page}" method="post">

<input type="hidden" name="no" value="${item.no}" />

</c:if>

 

 

<label>글제목:</label>

<input type="text" value="${item.title }" name="title" id="size" />

 

<label>글쓴이:</label>

<input type="text" name="writer" value="${item.writer }" />

 

<textarea rows="10" cols="10" class="ckeditor" name="content" >${item.content }</textarea>

</form>

 


BoardDto.java

( Get Sett Method 사용 하면 밑에 전부 자동 생성된다. Alt + Shift + s)

경로 : kr.or.javac.dto



BoardDao.java

경로 : kr.or.javac.dao



BoardController.java

경로 : kr.or.javac.controller


@Controller
@RequestMapping("/bd")
// value만 넣을 경우 바로 입력 가능
public class BoardController {




board.xml

경로 : SpringProject/src/main/java/kr/or/javac/maaper/board.xml


<mapper namespace="board">

<sql id="bdwhere">

<if test="value != null and value != ''">

where ${key} like '%'||#{value}||'%'

</if></sql>

 

<select id="getTotSize" parameterType="kr.or.javac.dto.BoardDto" resultType="int">

select count(no) from board

<include refid="bdwhere"/> </select>

 

<select id="getList" parameterType="kr.or.javac.dto.BoardDto"

resultType="kr.or.javac.dto.BoardDto">

select * from (select no, title, writer, wdate, rcount, rank() over(order by no desc) r from board <include refid="bdwhere"/>)

where r between #{firstRow} and #{lastRow}

order by no desc </select>

 

<insert id="write" parameterType="kr.or.javac.dto.BoardDto" >

insert into board(no, title, writer, content) values(seq_board.nextval, #{title}, #{writer}, #{content}) </insert>

 

<select id="read" parameterType="string" resultType="kr.or.javac.dto.BoardDto">

select * from board where no=#{no} </select>

 

<delete id="delete" parameterType="string">

delete from board where no=#{value} </delete>

 

<update id="update" parameterType="kr.or.javac.dto.BoardDto">

update board set title=#{title}, content=#{content} where no=#{no}

</update>

 

<update id="rcnt" parameterType="string">

update board set rcount=rcount+1 where no=#{value}

</update>




'Web > Spring' 카테고리의 다른 글

Spring JQuery 적용 하기  (0) 2012.08.09
Visual Svn  (0) 2012.08.09
Spring EMP 뿌려주기  (0) 2012.08.08
ibatise 설정  (0) 2012.08.08
Spring Post 한글 처리 방식  (0) 2012.08.08