<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:import url="header.jsp" />
<section>
<br><br>
<br>
<div align="center">
<font size=5><b> 회원 매출 조회</b></font>
<table border=1 width=500 height=250>
<tr align=center>
<td>회원번호</td>
<td>회원성명</td>
<td>고객등급</td>
<td>매출</td>
</tr>
<c:forEach items="${moneylist }" var="m">
<tr align=center>
<td>${m.getCustno()}</td>
<td>${m.getCustname()}</td>
<td>${m.getGrade()}</td>
<td>${m.getSprice()}</td>
</tr>
</c:forEach>
</table>
</div>
</section>
<c:import url="footer.jsp" />
SELECT m1.custno AS k1, m1.custname AS k2,
m1.grade AS k3, SUM(m2.price) AS k4
FROM member_tbl_02 m1 JOIN money_tbl_02 m2
ON m1.custno = m2.custno
GROUP BY m1.custno, m1.custname, m1.grade
ORDER BY SUM(m2.price) DESC ;
프로젝트를 구성한다.
Service
package com.springbook.biz.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.springbook.biz.common.MoneyVO;
import com.springbook.biz.dao.MoneyDAO;
@Service
public class MoneyServiceImpl implements MoneyService{
@Autowired
MoneyDAO dao;
@Override
public List<MoneyVO> moneylist() {
return dao.moneylist();
}
}
package com.springbook.biz.jungbo.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import com.springbook.biz.jungbo.common.MoneyVO;
@Repository
public class MoneyDAOImpl implements MoneyDAO{
@Autowired
JdbcTemplate jdbcTemplate;
String mlist_sql="select m1.custno as custno, m1.custname as custname, m1.grade as grade, sum(m2.price) as price from member_tbl_02 m1 join money_tbl_02 m2 on m1.custno = m2.custno group by m1.custno, m1.custname, m1.grade order by sum(m2.price) desc ";
@Override
public List<MoneyVO> moneylist() {
return jdbcTemplate.query(mlist_sql, new moneymapper());
}
}
class moneymapper implements RowMapper<MoneyVO>{
@Override
public MoneyVO mapRow(ResultSet rs, int rowNum) throws SQLException {
MoneyVO vo = new MoneyVO();
vo.setCustno(rs.getInt("custno"));
vo.setCustname(rs.getString("custname"));
vo.setGrade(rs.getString("grade"));
vo.setPrice(rs.getInt("price"));
return vo;
}
}
<c:if test="${m.getGrade() == 'A'}"> VIP </c:if>
<c:if test="${m.getGrade() == 'B'}"> 일반 </c:if>
<c:if test="${m.getGrade() == 'C'}"> 직원 </c:if>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber value="${m.price }" pattern="#,###" />