기록해! 정리해!

myBatis2 (3)- 검색창 본문

SpringBoot

myBatis2 (3)- 검색창

zsuling 2022. 10. 13. 12:10

1. Mapper

<select id="getExamList"  parameterType="com.rubypaper.exam.ExamVO"
                          resultType="com.rubypaper.exam.ExamVO" >
   select  *  from examtbl1013
   where 1 = 1
   <if test="ch1 == 'sno'">
    <![CDATA[
        and sno like '%' || #{ch2} || '%'
 ]]>
 </if>
 
 <if test="ch1 == 'sname'">
     <![CDATA[
        and sname like '%' || #{ch2} || '%'
 ]]>
 </if>
 order by sno desc
</select>

2.ExamVO

package com.rubypaper.exam;

import lombok.Data;

@Data
public class ExamVO {

	private String sno;
	private String sname;
	private int kor;
	private int eng;
	private int math;
	private int hist;
	
	private String ch1;
	private String ch2;
}

 

3. getExamList

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@taglib uri="http://java.sun.com/jstl/core_rt" 
          prefix="c" %>   

<%@ taglib prefix="fmt" 
     uri="http://java.sun.com/jsp/jstl/fmt"%>
     
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<h2> 성적 목록 보기 ( <a href=index.html>처음으로</a>) </h2>
<table border=1 >
<tr align="center"> 
 <th > 순번 </th> <th > 번호 </th> <th> 이름 </th> <th> 국어 </th>
 <th> 영어 </th> <th> 수학 </th> <th> 역사 </th>
 <th> 합계 </th><th> 평균 </th><th> 평균1 </th>

</tr>
<c:forEach  items="${li}"  var="m"  varStatus="status" >

<c:set var="sum"  value="${m.kor + m.eng + m.math + m.hist}" />
<c:set var="avg"  value="${sum / 4}" />
<c:set var="ksum"  value="${ksum + m.kor}" />
<c:set var="esum"  value="${esum + m.eng}" />
<c:set var="msum"  value="${msum + m.math}" />
<c:set var="hsum"  value="${hsum + m.hist}" />
<c:set var="ssum"  value="${ssum + sum}" />
<c:set var="asum"  value="${asum + avg}" />

<tr align="center"> 
 <td> ${status.count} </td>
 <td> ${m.sno} </td>
 <td><a href=getExam.do?sno=${m.sno}> ${m.sname}</a> </td>
 <td> ${m.kor} </td>
 <td> ${m.eng} </td>
 <td> ${m.math} </td>
 <td> ${m.hist} </td>
 <td> ${sum} </td>
 <td> ${avg} </td>
 <td> <fmt:formatNumber value="${avg}" pattern=".0" />  </td>

 </tr>
</c:forEach>

<tr align="center"> 
 <td colspan=3 > 누적합 </td>

 <td> ${ksum} </td>
 <td> ${esum}  </td>
 <td> ${msum}  </td>
 <td> ${hsum}  </td>
 <td> ${ssum} </td>
 <td> ${asum} </td>
 <td> ${asum} </td>

 </tr>

</table>

<form action=getExamList.do>
<select name=ch1>
  <option value=sno> 학 번 </option>
  <option value=sname> 이 름 </option>
</select> 
<input  type=text  name=ch2 >
<input  type=submit value="검색하기" >
</form>

</div>
</body>
</html>

 

>> 7번 검색

'SpringBoot' 카테고리의 다른 글

myBatis2 (5)- 자료실(사진)  (0) 2022.10.13
myBatis2 (4)- 자료실(사진)  (0) 2022.10.13
myBatis2 (2)- 상세보기  (0) 2022.10.13
myBatis2 (1)  (0) 2022.10.13
myBatis  (0) 2022.10.11
Comments