Session을 이용해 해당페이지 세션id를 가져오고
그 id에 해당하는 List 정보를 불러온다
1
2
3
4
5
|
public String cart(Model model, HttpSession httpSession){
String id = httpSession.getId();
List<Cart> list = dDAO.getItemCartList(id);
| cs |
1
2
3
4
5
6
|
// DAO
public List<Cart> getItemCartList(String a){
return sqlSession.selectList("D1.getItemCartList",a);
}
| cs |
DB에 p1_cart 테이블 과 p1_item 테이블을 innerJoin하여
p1_cart 에 있는 item_no, cart_cnt, cart_date 와
p1_item에 있는 item_name, item_price 를 가져와서 Cart vo에 넣는다
p1_cart 에 있는 item_no, cart_cnt, cart_date 와
p1_item에 있는 item_name, item_price 를 가져와서 Cart vo에 넣는다
1
2
3
4
5
6
7
8
9
10
11
12
|
// XML
<select id="getItemCartList" parameterType="String"
resultType="Cart">
SELECT
c.item_no, c.cart_cnt, c.cart_date,
i.item_name, i.item_price
FROM p1_cart c
INNER JOIN p1_item i
ON c.item_no = i.item_no
WHERE c.mem_id = #{mem_id}
</select>
| cs |
d
list안에 있는 여러 인덱스(item_no,cart_cnt,cart_daate,....기타등등) 를
반복문을 통해 가져와 tmp에 넣고
tmp안(여러 인덱스중 하나) getItem_no를 가져와 no로 생성한 다음
DAO의 getItemImg의 String 값으로 보내 준다.
list안에 있는 여러 인덱스(item_no,cart_cnt,cart_daate,....기타등등) 를
반복문을 통해 가져와 tmp에 넣고
tmp안(여러 인덱스중 하나) getItem_no를 가져와 no로 생성한 다음
DAO의 getItemImg의 String 값으로 보내 준다.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
// Controller
for(int i=0; i<list.size(); i++){
Cart tmp = list.get(i);
String no =tmp.getItem_no();
System.out.println(no);
List <String> imgs =dDAO.getItemImg(no);
tmp.setItem_img(imgs);
}
System.out.println();
model.addAttribute("list", list);
return "d1/cart";
}
| cs |
p1_item_img의 테이블에서 보내준 값이 item_no 같은 것 중에 item_img를 선택해서
리턴한다
1
2
3
4
5
|
// XML
<select id="getItemImgs" parameterType="String" resultType="String">
SELECT item_img FROM p1_item_img WHERE item_no=#{item_no}
</select>
|
잊지 않도록 한다
1
2
3
4
5
6
7
8
9
10
11
12
13
|
// VO
public class Cart {
private String mem_id= null;
private int cart_no=0;
private int cart_cnt=0;
private String item_no= null;
private String cart_date = null;
private String item_name = null;
private int item_price = 0;
private List<String> item_img = null;
| cs |
list에 있는 인덱스(VO의 값)들을 가져오기 위해 들을 tmp에 넣고 size만큼 자동 반복, tmp안에 item_no, cart_cnt 기타 등등 value에 넣어서 화면에 띄우게 한다
이미지의 경우 list로 감싸져 있어 여러 인덱스를 가지고 있으니
tmp1로 지정해 주고 반복문을 돌려 img값들을 가져온후
if 구절을 통해 인덱스의 첫번째 값(첫번째 사진을 의미) i.first 만 출력한다. tmp1을 출력함
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
// JSP
<c:forEach var="tmp" items="${list}">
<tr>
<th><input type="hidden" name="item_no[]" value="${tmp.item_no}"/>${tmp.item_no}</th>
<th>${tmp.item_name}</th>
<th>${tmp.item_price}</th>
<th><input type="hidden" name="cart_cnt[]" value="${tmp.cart_cnt}"/>${tmp.cart_cnt}</th>
<th>${tmp.cart_date}</th>
<c:forEach var="tmp1" items="${tmp.item_img}" varStatus="i">
<c:if test="${i.first}">
<th><img src="resources/images/${tmp1}" width="60px" height="60px" /></th>
</c:if>
</c:forEach>
</tr>
</c:forEach>
| cs |
댓글 없음:
댓글 쓰기