COST 라는 테이블에 소속된 칼럼들 입니다.
ID_COST
ID_TRANSACTION
COST_CONTENT
ID_EMPLOYEE
COST_AMOUNT
ID_PROJECT
ID_PAYMENT
COST_DATE
COST_NOTE
ID_DEPARTMENT
ID_CATEGORY
ID_COST를 빼고 나머지 ID가 앞에 붙은 애들은 전부 다른 테이블의 ID 칼럼과 외래키 처리가
된 것들 이구요. jsp 페이지에서 검색기능을 구현중인데.. 그냥 검색을 태우면 결과값이
ID가 붙은애들은 전부 number형이라서 숫자만 출력이 됩니다. 저는 검색하고 jsp 화면에 뿌려줄때는
ID값에 해당하는 name칼럼의 String값을 뿌려줘야 되는데요.. 뭘 어떻게 해도 계속 숫자만 검색이
되고.. 어떻게 변형을 해야할지 모르겠습니다.. 조언좀 부탁드립니다...
검색 Dao 로직 입니다.
public List<CostBean> search(String search_input, int startRow, int endRow) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
String sql = " select * from (select rownum rnum, a.* from "
+ " ((select * from cost"
+ " where id_transaction like '%" + search_input + "%' "
+ " OR cost_content like '%" + search_input + "%'"
+ " OR TO_DATE(cost_date,'YYYY-MM-DD') like '%" + search_input + "%'"
+ " OR id_category like '%" + search_input + "%' "
+ " OR id_payment like '%" + search_input + "%' "
+ " OR id_project like '%" + search_input + "%' order by cost_date desc) a))"
+ " where (rnum >=? and rnum <=?)"
+ " order by rnum asc";
conn = ds.getConnection();
pstmt = conn.prepareStatement(sql);
int i = 0;
pstmt.setInt(++i, startRow);
pstmt.setInt(++i, endRow);
rs = pstmt.executeQuery();
List<CostBean> page_list = new ArrayList<CostBean>();
while (rs.next()) {
CostBean bean = new CostBean();
bean.setId_cost(rs.getInt("id_cost"));
bean.setCost_date(rs.getString("cost_date").substring(0, 10));
bean.setId_transaction(rs.getInt("id_transaction"));
bean.setId_employee(rs.getString("id_employee"));
bean.setId_category(rs.getInt("id_category"));
bean.setCost_content(rs.getString("cost_content"));
bean.setCost_amount(rs.getInt("cost_amount"));
bean.setId_payment(rs.getInt("id_payment"));
bean.setId_project(rs.getInt("id_project"));
bean.setCost_note(rs.getString("cost_note"));
page_list.add(bean);
}
return page_list;
} catch (Exception e) {
e.printStackTrace();
} finally {
close(rs);
close(conn);
close(pstmt);
}
return null;
}
페이징 처리해서 jsp 로 보내기 직전 java파일 입니다.
// 페이징
String p = request.getParameter("page");
int page = 1;
if (p != null) {
page = Integer.parseInt(p);
}
int startRow = 10 * (page - 1) + 1;
int endRow = startRow + 9;
CostDao Dao = new CostDao();
// 검색
// String[] search_array = { "날짜", "수입/지출", "카테고리", "내용", "결제수단",
// "프로젝트", "비고" };
String[] search_value = request.getParameterValues("search_value");
String search_input = request.getParameter("search_input");
String search_values = null;
List<CategoryBean> category_list = new ArrayList<CategoryBean>();
int id_category = 0;
for (int i = 0; i < search_value.length; i++) {
request.setAttribute("search_input", search_input);
List<CostBean> page_list = Dao.search(search_input, startRow, endRow);
for(int j = 0; j < page_list.size(); j++){
id_category = page_list.get(j).getId_category();
category_list = Dao.Search_category_name(id_category);
}
request.setAttribute("category_list", category_list);
request.setAttribute("page_list", page_list);
}
String count = Dao.Count();
int Count = Integer.parseInt(count);
int ListCount = (Count / 10) + 1;
int previous = page - (page % 5) - 1;
if (previous < 1) {
previous = 1;
}
int next = previous + 6;
if (next > ListCount)
next = ListCount;
request.setAttribute("previous", previous);
request.setAttribute("next", next);
request.setAttribute("ListCount", ListCount);
request.setAttribute("page", page);
request.setAttribute("Count", Count);
뿌려주는 jsp 파일 입니다.
<c:forEach var="listbean" items="${ page_list }">
<c:if test="${ session_employee eq listbean.id_employee }">
<div class="rowDiv" style="white-space: nowrap; display: table;">
<div class="table_align cellDiv"
style="width: 30px; text-align: center; vertical-align: middle; margin-right: 5px;">
<input style="margin-left:5px;" type="checkbox" class="checkbox" name="id_cost"
id="id_cost" value="${ listbean.id_cost }">
</div>
<div class="table_align cellDiv" style="width: 100px">${ listbean.cost_date }
</div>
<div class="table_align cellDiv" style="width: 100px">${ listbean.id_transaction }</div>
<c:forEach var="category_listbean" items="${ category_list }">
<c:choose>
<c:when test="${ category_listbean.id_category eq listbean.id_category }">
<div class="table_align cellDiv" style="width: 100px">${ category_listbean.category_name }</div>
</c:when>
<c:when test="${ category_listbean.id_category ne listbean.id_category }">
<div class="table_align cellDiv" style="width: 100px">${ category_listbean.id_category }</div>
</c:when>
</c:choose>
</c:forEach>
<div class="table_align cellDiv" style="width: 300px;">
<a href="#" onclick="modify_popup('Board_Modify_View.com?id_cost=${ listbean.id_cost }')">${ listbean.cost_content }</a>
<c:if test="${ listbean.cost_date eq year }">
<img src="${ contextPath }/images/new.jpg">
</c:if>
</div>
<div class="table_align cellDiv" style="width: 100px; text-align: right;">
<fmt:formatNumber value="${ listbean.cost_amount }" groupingUsed="true"/></div>
<div class="table_align cellDiv" style="width: 100px">${ listbean.id_payment }</div>
<div class="table_align cellDiv" style="width: 100px">${ listbean.id_project }</div>
<!-- 테이블 content 부분 넓이 조절 width -->
<div class="table_align cellDiv lastCell" style="width: 327px; margin-right: 20px;">${ listbean.cost_note }</div>
</div>
</c:if>
</c:forEach>
</div>