DB

Collectible에대한 DB컬럼
Image에대한 DB컬럼

  • 이미지 게시판에 대한 DB쿼리 
  • List , Detail 부분에서 join을 사용해서 쿼리를 생성 했기에 mapper.xml에 두개의 resultMap을 선언 후 사용

★목록부

=> 목록부는 일반 게시판 List에대한 메서드와 같음

Controller

	@Override
	@RequestMapping(value="/collectibleList.do" ,method={RequestMethod.POST,RequestMethod.GET})
	public ModelAndView collectibleList(HttpServletRequest request, HttpServletResponse response)  throws Exception {
		String viewName=(String)request.getAttribute("viewName");
		ModelAndView mav = new ModelAndView(viewName);
		
		List<CollectibleVO> collectibleList=collectibleService.collectibleList();
		mav.addObject("collectible", collectibleList);

		return mav;
		
	}

 

Service

	@Override
	public List<CollectibleVO> collectibleList() throws Exception{
		return collectibleDAO.selectAllCollectibleList();
	}

DAO

	@Override
	public List<CollectibleVO>selectAllCollectibleList() throws DataAccessException {
		ArrayList<CollectibleVO>  CollectibleList=(ArrayList)sqlSession.selectList("mapper.collectible.selectAllCollectibleList",condMap);
		return CollectibleList;
	}

Mapper

	<select id="selectAllCollectibleList" resultMap="goodsResult" parameterType="java.util.Map">  
   select * 
   		from(
		selectcol.goods_id,col.goods_title,col.goods_author
		(
   			select image.fileName
   			from GALLERY_IMAGE image
    		where image.goods_id = col.goods_id
		)as goods_fileName
    		from gallery_collectible col
    		)
		ORDER BY goods_id DESC
	</select>
  • collectible에 대한 컬럼과 이미지에대한 컬럼을 join하여 조회목록 쿼리 작성

Jsp

	<div class="gallery">
		<c:choose>
				<c:when test="${empty collectible }">

					<p style="text-align:center;">조회된 상품이 없습니다.</p>

				</c:when>
				<c:otherwise>
		<c:forEach var="item" items="${collectible}">
			<div class="collectible">
			<h1> </h1>
					<a href='<c:url value='/collectible/collectibleDetail.do?goods_id=${item.goods_id}}'/>'>${Notice.title }
					<!-- 이미지를 클릭 시 상세 페이지를 가기 위해 1px 짜리 이미지를
                     썸네일 사진 안쪽에 삽입함-->
                    <img class="link" src="${contextPath}/resources/image/1px.gif"></a> 
					
                    <!-- 썸네일 메서드에 대한 변수 선언한 것을 jsp에서 사용 -->
					<img width="180" height="150"
					src="${contextPath}/thumbnails.do?goods_id=${item.goods_id}&fileName=${item.goods_fileName}">

				<div class="color_black">${item.goods_title }</div>
				<div class="desc">${item.goods_author} </div>
			</div>
		</c:forEach>
		</c:otherwise>
		</c:choose>

--------------------------------------------------------------------------------------

-상세보기

Controller

	@Override
	@RequestMapping(value="collectibleDetail.do", method=RequestMethod.GET)
	public ModelAndView collectibleDetail(@RequestParam("goods_id") int goods_id, 
				HttpServletRequest request, HttpServletResponse response)throws Exception{
		String viewName=(String)request.getAttribute("viewName");
		collectibleVO = collectibleService.collectibleDetail(goods_id);
		ModelAndView mav = new ModelAndView();
		mav.setViewName(viewName);
		mav.addObject("collectible",collectibleVO);
		return mav;
	}

Service

	@Override
	public CollectibleVO collectibleDetail(int goods_id)throws Exception{
		CollectibleVO collectibleVO = collectibleDAO.selectCollectibleDetail(goods_id);
		return collectibleVO;
	}

DAO

	@Override
	public CollectibleVO selectCollectibleDetail(int goods_id)throws DataAccessException{
		return sqlSession.selectOne("mapper.collectible.selectCollectibleDetail",goods_id);
	}

 Mapper

	<select id="selectCollectibleDetail" parameterType="int" resultMap="goodsResult" >
		<![CDATA[
			select col.goods_id, col.goods_title, col.goods_year, col.goods_no ,col.goods_author,col.goods_year,
			col.goods_stuff, col.goods_standard, col.goods_note, col.goods_status, (image.fileName) as goods_fileName 
			from GALLERY_COLLECTIBLE col, GALLERY_IMAGE image
			where col.goods_id = image.goods_id
			and image.fileType = 'main_image'
			and col.goods_id = #{col.goods_id}
		]]>
	</select>

Jsp

	<form name="form1" method="post">
		<h1></h1>
		<input type="hidden" name="member_id" value="${memberInfo.member_id}" />
		<div style="text-align: center">
			<img width="300" height="154"
				src="${contextPath}/thumbnails.do?goods_id=${collectible.goods_id}&fileName=${collectible.goods_fileName}">
		</div>

		<table>
			<tbody>
				<tr>
					<td>제목</td>
					<td>${collectible.goods_title}</td>
				</tr>
				<tr>
					<td>등록번호</td>
					<td>${collectible.goods_no}</td>
				</tr>
				<tr>
					<td>작가</td>
					<td>${collectible.goods_author}</td>
				</tr>
				<tr>
					<td>제작년도</td>
					<td>${collectible.goods_year}</td>
				</tr>
				<tr>
					<td>재료 및 기법</td>
					<td>${collectible.goods_stuff}</td>
				</tr>
				<tr>
					<td>작품규격</td>
					<td>${collectible.goods_standard}</td>
				</tr>
				<tr>
					<td>내용</td>
					<td>${collectible.goods_note}</td>
				</tr>
		</table>
					<a style='cursor: pointer;'
			href='<c:url value='/collectible/collectibleList.do'/>'>▶목록으로</a>
	</form>
복사했습니다!