728x90
반응형
현재 spring3.0 + ibatis로 게시판 만드는 중인데요
조회수 증가하는 법을 잘 모르겠습니다.
쿼리문은 맞는데 자꾸 오류가 나네요 ㅠㅠ
뭐가 잘못된걸까요..?
검은 글씨랑 빨간것만 보시면 될듯(?) 합니다... 도와주세요 ㅠㅠ
============xml==================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="BbsDAO">
<typeAlias alias="bbsVO" type="com.kicsystems.bbs.service.BbsVO" />
<typeAlias alias="cateVO" type="com.kicsystems.bbs.service.CateVO" />
<resultMap class="bbsVO" id="bbsVOMap">
<result property="bbsId" column="BBS_ID" />
<result property="title" column="TITLE" />
<result property="content" column="CONTENT" />
<result property="fileId" column="FILE_ID" />
<result property="regId" column="REG_ID" />
<result property="regDt" column="REG_DT" />
<result property="hit" column="HIT" nullValue="0"/>
</resultMap>
<!-- <resultMap class="cateVO" id="cateVOMap">
<result property="cateId" column="CATE_ID" />
<result property="cateNm" column="CATE_NM" />
<result property="useYn" column="USE_YN" />
</resultMap> -->
<select id="BbsDAO.selectBbsList" parameterClass="bbsVO" resultMap="bbsVOMap">
SELECT
A.CATE_ID, A.CATE_NM, B.BBS_ID, B.CATE_ID, B.TITLE,
B.CONTENT, B.FILE_ID, B.REG_ID, B.REG_DT, B.HIT
FROM
TN_BBS_CATE A
LEFT OUTER JOIN
TN_BBS_BOARD B
ON A.CATE_ID = B.CATE_ID
<![CDATA[
WHERE
A.CATE_ID = #cateId#
]]>
</select>
<select id="BbsDAO.selectBbs" parameterClass="bbsVO" resultClass="bbsVO">
SELECT
A.CATE_ID AS cateId
, A.CATE_NM AS cateNm
, B.BBS_ID AS bbsId
, B.TITLE AS title
, B.CONTENT AS content
, B.FILE_ID AS fileId
, B.REG_ID AS regId
, B.REG_DT AS regDt
, B.HIT AS hit
FROM
TN_BBS_CATE A
LEFT OUTER JOIN
TN_BBS_BOARD B
ON A.CATE_ID = B.CATE_ID
<![CDATA[
WHERE
B.BBS_ID = #bbsId#
]]>
</select>
<select id="BbsDAO.selectCateList" parameterClass="bbsVO" resultClass="cateVO">
<![CDATA[
SELECT
CATE_ID cateId, CATE_NM cateNm
FROM
TN_BBS_CATE
]]>
</select>
<insert id="BbsDAO.insertBbs" parameterClass="bbsVO" >
<![CDATA[
INSERT
INTO TN_BBS_BOARD
(BBS_ID, CATE_ID, TITLE, CONTENT,
FILE_ID, REG_ID, REG_DT, HIT)
VALUES
(#bbsId#, #cateId#, #title#, #content#,
#fileId#, #regId#, TO_DATE(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'), '0')
]]>
</insert>
<delete id="BbsDAO.deleteBbs" parameterClass="bbsVO">
<![CDATA[
DELETE
FROM TN_BBS_BOARD
WHERE
BBS_ID = #bbsId#
]]>
</delete>
<update id="BbsDAO.updateBbs" parameterClass="bbsVO">
<![CDATA[
UPDATE TN_BBS_BOARD SET
CATE_ID = #cateId#
,REG_ID = #regId#
,TITLE = #title#
,CONTENT = #content#
,REG_DT = TO_DATE(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')
WHERE REG_ID = #regId#
]]>
</update>
<select id="BbsDAO.selectBbsListCnt" parameterClass="bbsVO" resultClass="int">
SELECT COUNT(A.BBS_ID)
FROM TN_BBS_BOARD A
WHERE 1 = 1
</select>
<update id="BbsDAO.updateBbsHit" parameterClass="bbsVO" >
<![CDATA[
UPDATE
TN_BBS_BOARD
SET
HIT = HIT + 1
WHERE BBS_ID = #bbsId#
]]>
</update>
</sqlMap>
====================================================================
============= Controller =========================
package com.kicsystems.bbs.web;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import com.cmm.idgnr.IdGnrService;
import com.cmm.mvc.ui.PaginationInfo;
import com.cmm.mvc.ui.PaginationUtil;
import com.kicsystems.bbs.service.BbsService;
import com.kicsystems.bbs.service.BbsVO;
@Controller
public class BbsController {
@Resource(name = "bbsService")
private BbsService bbsService;
@Resource(name = "bbsIdGnrService")
private IdGnrService bbsIdGnrService;
// 글 목록
/*@RequestMapping("/bbs/bbsList.do")
public String selectBbsList(@ModelAttribute("bbsVO") BbsVO bbsVO, ModelMap model) throws Exception {
model.addAttribute("list", bbsService.selectBbsList(bbsVO));
return "bbs/bbsList";
}*/
// 페이징
@RequestMapping("/bbs/bbsList.do")
public String list(@ModelAttribute("bbsVO") BbsVO bbsVO, Model model) throws Exception {
PaginationInfo paginationInfo = new PaginationInfo();
paginationInfo.setCurrentPageNo(bbsVO.getPageIndex());
bbsVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
List<BbsVO> list = bbsService.selectBbsList(bbsVO);
model.addAttribute("list", list);
int totCnt = bbsService.selectBbsListCnt(bbsVO);
paginationInfo.setSearchRecordCount(totCnt);
paginationInfo.setParams(PaginationUtil.resolveParameter());
model.addAttribute("paginationInfo", paginationInfo);
model.addAttribute("BODY", "bbs/bbsList");
return "bbs/bbsList";
}
// 글 등록 / 수정
@RequestMapping("/bbs/bbsForm.do")
public String bbsForm(@ModelAttribute("bbsVO") BbsVO bbsVO, ModelMap model) throws Exception{
String cateId = bbsVO.getCateId();
bbsVO = bbsService.selectBbs(bbsVO);
if(bbsVO == null){
bbsVO = new BbsVO();
bbsVO.setCateId(cateId);
}
model.addAttribute("bbsVO", bbsVO);
model.addAttribute("cateList", bbsService.selectCateList());
return "bbs/bbsForm";
}
// 글 등록 / 수정 처리
@RequestMapping("/bbs/bbsSubmit.do")
public String bbsSubmit(@ModelAttribute("bbsVO") BbsVO bbsVO) throws Exception {
String cateId = bbsVO.getCateId();
if(StringUtils.hasText(bbsVO.getBbsId())) {
bbsService.updateBbs(bbsVO);
}else {
String bbsId = bbsIdGnrService.getNextStringId();
bbsVO.setBbsId(bbsId);
bbsService.insertBbs(bbsVO);
}
return "redirect:/bbs/bbsList.do?cateId="+cateId;
}
// 글 삭제
@RequestMapping(value= "/bbs/deleteBbs.do")
public String deleteBbs(@ModelAttribute("bbsVO") BbsVO bbsVO) throws Exception {
String cateId = bbsVO.getCateId();
bbsService.deleteBbs(bbsVO);
if(cateId == null){
bbsVO = new BbsVO();
bbsVO.setCateId(cateId);
}
return "redirect:/bbs/bbsList.do?cateId=" + cateId;
}
// 상세 보기 페이지
@RequestMapping("/bbs/bbsView.do")
public String bbsView(@ModelAttribute("bbsVO") BbsVO bbsVO, ModelMap model) throws Exception{
bbsService.updateBbsHit(bbsVO);
model.addAttribute("list", bbsService.selectBbs(bbsVO));
return "bbs/bbsView";
}
}
==================================== 오류 ==================================
nested exception is java.sql.SQLException: Update statements cannot be executed as a query.
답변 :
상세보기 페이지
// 상세 보기 페이지
@RequestMapping("/bbs/bbsView.do")
public String bbsView(@ModelAttribute("bbsVO") BbsVO bbsVO, ModelMap model) throws Exception{
bbsService.updateBbsHit(bbsVO);
model.addAttribute("list", bbsService.selectBbs(bbsVO));
return "bbs/bbsView";
}
}
위 소스중 bbsVO set 시키는 부분이 없네요.
tip. 업데이트 시키는데 key 값 하나만 필요하면 파라메터 스트링으로 받으면 되는데
굳이 vo 로 받는 이유가 있나요?
728x90
반응형
'SQL > IBATIS' 카테고리의 다른 글
ibatis 글자수로 조건 줄때 (0) | 2014.04.12 |
---|---|
동적 SQL (0) | 2014.03.25 |
ibatis 동적 쿼리 예제 (0) | 2014.03.25 |
dynamic 태그, isParameterPresent, removeFirstPrepend 설명 (0) | 2014.03.25 |
[iBatis] iBatis 에서 Dynamic Mapped Statement 사용시 문제 (0) | 2014.02.19 |
SqlMapClient API를 통해 statement를 수행하기. (0) | 2014.02.19 |
배치(Batches) (0) | 2014.02.19 |
Data Mapper로 프로그래밍하기: The API (0) | 2014.02.19 |