<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">여기는 검색할 자료를 입력하는 곳입니다.</h3>
<form action="search2">
<table border="1" align="center">
<tr>
<th>분류</th>
<th>데이터</th>
</tr>
<tr>
<td>
<select name="item">
<option value="id">아이디</option>
<option value="name">이름</option>
</select>
</td>
<td><input type="text" name="value"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="초기화">
</td>
</tr>
</table>
</form>
<div align="center"><a href ="/com5_001/">인덱스로</a></div>
</body>
</html>
package com.ezen.kim5_001;
import java.util.ArrayList;
public interface Service {
//CRUD 기능의 추상메소드
public void insert(String id,String pw,String name,String phone,int jum);
public ArrayList<OfficeDTO> out();
public void delete(String did);
public ArrayList<OfficeDTO> modify(String mid);
public void modify2(String id,String pw,String name,String phone,int jum);
public ArrayList<OfficeDTO> searchid(String value);
public ArrayList<OfficeDTO> searchname(String value);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ezen.kim5_001.Service">
<insert id="insert">
insert into db02241 values (#{param1},#{param2},#{param3},#{param4},#{param5})
</insert>
<select id="out" resultType="com.ezen.kim5_001.OfficeDTO">
select * from db02241 order by name desc
</select>
<delete id="delete">
delete from db02241 where id=#{param1}
</delete>
<select id="modify" resultType="com.ezen.kim5_001.OfficeDTO">
select * from db02241 where id=#{param1}
</select>
<update id="modify2">
update db02241 set pw=#{param2},name=#{param3},phone=#{param4},jum=#{param5} where id=#{param1}
</update>
<select id="searchid" resultType="com.ezen.kim5_001.OfficeDTO">
select * from db02241 where id like '%'||#{param1}||'%'
</select>
<select id="searchname" resultType="com.ezen.kim5_001.OfficeDTO">
select * from db02241 where name like '%'||#{param1}||'%'
</select>
</mapper>
package com.ezen.kim5_001;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomeController {
@Autowired
SqlSession sqlsession;
@RequestMapping(value="/")
public String ko0() {
return "index";
}
@RequestMapping(value="/in")
public String ko1() {
return "input";
}
@RequestMapping(value="/save")
public String ko2(HttpServletRequest request){
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String name = request.getParameter("name");
String phone = request.getParameter("phone");
int jum = Integer.parseInt(request.getParameter("jum"));
Service ss = sqlsession.getMapper(Service.class);
ss.insert(id,pw,name,phone,jum);
return "redirect:in";
}
@RequestMapping(value="/out")
public String ko3(Model mo){
Service ss = sqlsession.getMapper(Service.class);
ArrayList<OfficeDTO> list= ss.out();
mo.addAttribute("list", list);
return "output";
}
@RequestMapping(value="/delete")
public String ko4(HttpServletRequest request){
String did = request.getParameter("id");
Service ss = sqlsession.getMapper(Service.class);
ss.delete(did);
return "redirect:out";
}
@RequestMapping(value="/modify")
public String ko5(HttpServletRequest request,Model mo){
String mid = request.getParameter("id");
Service ss = sqlsession.getMapper(Service.class);
ArrayList<OfficeDTO> list= ss.modify(mid);
mo.addAttribute("list", list);
return "out2";
}
@RequestMapping(value="/modify2")
public String ko6(HttpServletRequest request){
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String name = request.getParameter("name");
String phone = request.getParameter("phone");
int jum = Integer.parseInt(request.getParameter("jum"));
Service ss = sqlsession.getMapper(Service.class);
ss.modify2(id,pw,name,phone,jum);
return "redirect:out";
}
@RequestMapping(value="/search")
public String ko7(){
return "searchform";
}
@RequestMapping(value="/search2")
public String ko8(HttpServletRequest request,Model mo){
String item = request.getParameter("item");
String value = request.getParameter("value");
Service ss = sqlsession.getMapper(Service.class);
ArrayList<OfficeDTO> list = null;
if(item.equals("id")) {
list = ss.searchid(value);
}
else {
list = ss.searchname(value);
}
mo.addAttribute("list", list);
return "output";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="in">입력</a><br>
<a href="out">출력</a><br>
<a href="search">검색</a><br>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<script>
function chooseForm(radioName) {
var radios = document.getElementsByName(radioName);
for (var i = 0, length = radios.length; i < length; i++) {
document.getElementById('form_' + radios[i].value).style.display = 'none';
if (radios[i].checked) {
document.getElementById('form_' + radios[i].value).style.display = 'block';
}
}
}
</script>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<label><input type="radio" name="formType" value="1" checked onclick="chooseForm(this.name)" />중간</label>
<label><input type="radio" name="formType" value="2" onclick="chooseForm(this.name)" />기말</label>
<div id="form_1">
<h2>중간고사</h2>
<form action="save1" method="post">
<table border="1">
<tr>
<th>시험구분</th>
<td><input type="radio" name="bigo" value="중간" checked="checked">중간</td>
</tr>
<tr>
<th>학번</th>
<td><input type="text" name="num"></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name"></td>
</tr>
<tr>
<th>국어</th>
<td><input type="text" name="kor"></td>
</tr>
<tr>
<th>영어</th>
<td><input type="text" name="eng"></td>
</tr>
<tr>
<th>수학</th>
<td><input type="text" name="mat"></td>
</tr>
<tr>
<th>과학</th>
<td><input type="text" name="sci"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
</div>
<div id="form_2" style="display: none;">
<h2>기말고사</h2>
<form action="save2" method="post">
<table border="1">
<tr>
<th>시험구분</th>
<td><input type="radio" name="bigo" value="기말" checked="checked">기말</td>
</tr>
<tr>
<th>학번</th>
<td><input type="text" name="num"></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name"></td>
</tr>
<tr>
<th>국어</th>
<td><input type="text" name="kor"></td>
</tr>
<tr>
<th>영어</th>
<td><input type="text" name="eng"></td>
</tr>
<tr>
<th>수학</th>
<td><input type="text" name="mat"></td>
</tr>
<tr>
<th>과학</th>
<td><input type="text" name="sci"></td>
</tr>
<tr>
<th>기술</th>
<td><input type="text" name="tech"></td>
</tr>
<tr>
<th>음악</th>
<td><input type="text" name="mus"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
</div>
<a href="/kim6_002">홈으로</a>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
th,td {
text-align: center;
}
</style>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2 align="center">성적출력데이터</h2>
<table border="1" align="center">
<tr>
<th>학번</th><th>이름</th><th>국어평균</th><th>영어평균</th><th>수학평균</th>
<th>과학평균</th><th>기술(기말)</th><th>음악(기말)</th><th>총점</th><th>평균</th>
<th>중간고사</th><th>기말고사</th>
</tr>
<c:forEach items="${list}" var="list">
<tr>
<td>${list.num}</td><td>${list.name}</td><td>${list.kor}</td>
<td>${list.eng}</td><td>${list.mat}</td><td>${list.sci}</td>
<td>${list.tech}</td><td>${list.mus}</td><td>${list.tot}</td>
<td>${list.avg}</td>
<td>
<a href="delete1?name=${list.name}">❌</a>
<a href="modify1?name=${list.name}">✅</a>
</td>
<td>
<a href="delete2?name=${list.name}">❌</a>
<a href="modify2?name=${list.name}">✅</a>
</td>
</tr>
</c:forEach>
</table>
<div align="center">
<a href="/kim6_002">홈으로</a>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2 align="center">중간고사</h2>
<form action="modify3" method="post">
<table border="1" align="center">
<c:forEach items="${list}" var="list">
<tr>
<th>시험구분</th>
<td><input type="radio" name="bigo" value="중간" checked="checked">중간</td>
</tr>
<tr>
<th>학번</th>
<td><input type="text" name="num" value="${list.num}" readonly></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name" value="${list.name}" readonly></td>
</tr>
<tr>
<th>국어</th>
<td><input type="text" name="kor" value="${list.kor}"></td>
</tr>
<tr>
<th>영어</th>
<td><input type="text" name="eng" value="${list.eng}"></td>
</tr>
<tr>
<th>수학</th>
<td><input type="text" name="mat" value="${list.mat}"></td>
</tr>
<tr>
<th>과학</th>
<td><input type="text" name="sci" value="${list.sci}"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="리셋">
</td>
</tr>
</c:forEach>
</table>
</form>
<div align="center">
<a href="/kim6_002">홈으로</a>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2 align="center">기말고사</h2>
<form action="modify4" method="post">
<table border="1" align="center">
<c:forEach items="${list}" var="list">
<tr>
<th>시험구분</th>
<td><input type="radio" name="bigo" value="기말" checked="checked">기말</td>
</tr>
<tr>
<th>학번</th>
<td><input type="text" name="num" value="${list.num}" readonly></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name" value="${list.name}" readonly></td>
</tr>
<tr>
<th>국어</th>
<td><input type="text" name="kor" value="${list.kor}"></td>
</tr>
<tr>
<th>영어</th>
<td><input type="text" name="eng" value="${list.eng}"></td>
</tr>
<tr>
<th>수학</th>
<td><input type="text" name="mat" value="${list.mat}"></td>
</tr>
<tr>
<th>과학</th>
<td><input type="text" name="sci" value="${list.sci}"></td>
</tr>
<tr>
<th>기술</th>
<td><input type="text" name="tech" value="${list.tech}"></td>
</tr>
<tr>
<th>음악</th>
<td><input type="text" name="mus" value="${list.mus}"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="리셋">
</td>
</tr>
</c:forEach>
</table>
</form>
<div align="center">
<a href="/kim6_002">홈으로</a>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="search2">
<table border="1" align="center">
<tr>
<th>분류</th>
<th>데이터</th>
</tr>
<tr>
<td>
<select name="item">
<option value="num">학번</option>
</select>
</td>
<td><input type="text" name="value"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="초기화">
</td>
</tr>
</table>
</form>
<div align="center">
<a href="/kim6_002">홈으로</a>
</div>
</body>
</html>
package com.ezen.kim6_002;
import java.util.ArrayList;
public interface Service {
public void insert(String bigo,int num,String name,int kor,int eng,int mat,int sci);
public void insert2(String bigo,int num,String name,int kor,int eng,int mat,int sci,int tech,int mus);
public ArrayList<ScoreDTO> out();
public void delete1(String dname);
public void delete2(String dname);
public ArrayList<ScoreDTO> modify1(String mname);
public void modify3(String bigo,int num,String name,int kor,int eng,int mat,int sci);
public ArrayList<ScoreDTO> modify2(String mname);
public void modify4(String bigo,int num,String name,int kor,int eng,int mat,int sci,int tech,int mus);
public ArrayList<ScoreDTO> search2(String value);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ezen.kim6_002.Service">
<insert id="insert">
insert into db02273 values (#{param1},#{param2},#{param3},#{param4},#{param5},#{param6},#{param7})
</insert>
<insert id="insert2">
insert into db02272 values (#{param1},#{param2},#{param3},#{param4},#{param5},#{param6},#{param7},#{param8},#{param9})
</insert>
<select id="out" resultType="com.ezen.kim6_002.ScoreDTO">
select db2.num as num,db2.name as name,(db2.kor+db3.kor)/2 as kor,(db2.eng+db3.eng)/2 as eng,
(db2.mat+db3.mat)/2 as mat,(db2.sci+db3.sci)/2 as sci,db2.tech as tech,db2.mus as mus,
(db2.kor+db3.kor+db2.eng+db3.eng+db2.mat+db3.mat+db2.sci+db3.sci+db2.tech+db2.mus) as tot,
(db2.kor+db3.kor+db2.eng+db3.eng+db2.mat+db3.mat+db2.sci+db3.sci+db2.tech+db2.mus)/10 as avg
from db02272 db2,db02273 db3 where db3.num = db2.num
</select>
<delete id="delete1">
delete from db02273 where name = #{param1}
</delete>
<delete id="delete2">
delete from db02272 where name = #{param1}
</delete>
<select id="modify1" resultType="com.ezen.kim6_002.ScoreDTO">
select * from db02273 where name = #{param1}
</select>
<update id="modify3">
update db02273 set bigo=#{param1},num=#{param2},kor=#{param4},eng=#{param5},mat=#{param6},sci=#{param7} where name=#{param3}
</update>
<select id="modify2" resultType="com.ezen.kim6_002.ScoreDTO">
select * from db02272 where name = #{param1}
</select>
<update id="modify4">
update db02272 set bigo=#{param1},num=#{param2},kor=#{param4},eng=#{param5},mat=#{param6},sci=#{param7},tech=#{param8},mus=#{param9} where name=#{param3}
</update>
<select id="search2" resultType="com.ezen.kim6_002.ScoreDTO">
select db2.num as num,db2.name as name,(db2.kor+db3.kor)/2 as kor,(db2.eng+db3.eng)/2 as eng,
(db2.mat+db3.mat)/2 as mat,(db2.sci+db3.sci)/2 as sci,db2.tech as tech,db2.mus as mus,
(db2.kor+db3.kor+db2.eng+db3.eng+db2.mat+db3.mat+db2.sci+db3.sci+db2.tech+db2.mus) as tot,
(db2.kor+db3.kor+db2.eng+db3.eng+db2.mat+db3.mat+db2.sci+db3.sci+db2.tech+db2.mus)/10 as avg
from db02272 db2,db02273 db3 where db3.num = db2.num and db2.num=#{param1}
</select>
</mapper>
package com.ezen.kim6_002;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@Autowired
SqlSession sqlsession;
@RequestMapping(value="/")
public String ko1() {
return "index";
}
@RequestMapping(value="/in")
public String ko2() {
return "input";
}
@RequestMapping(value="save1")
public String ko3(HttpServletRequest request) {
String bigo = request.getParameter("bigo");
int num = Integer.parseInt(request.getParameter("num"));
String name = request.getParameter("name");
int kor = Integer.parseInt(request.getParameter("kor"));
int eng = Integer.parseInt(request.getParameter("eng"));
int mat = Integer.parseInt(request.getParameter("mat"));
int sci = Integer.parseInt(request.getParameter("sci"));
Service ss = sqlsession.getMapper(Service.class);
ss.insert(bigo,num,name,kor,eng,mat,sci);
return "redirect:in";
}
@RequestMapping(value="save2")
public String ko4(HttpServletRequest request) {
String bigo = request.getParameter("bigo");
int num = Integer.parseInt(request.getParameter("num"));
String name = request.getParameter("name");
int kor = Integer.parseInt(request.getParameter("kor"));
int eng = Integer.parseInt(request.getParameter("eng"));
int mat = Integer.parseInt(request.getParameter("mat"));
int sci = Integer.parseInt(request.getParameter("sci"));
int tech = Integer.parseInt(request.getParameter("tech"));
int mus = Integer.parseInt(request.getParameter("mus"));
Service ss = sqlsession.getMapper(Service.class);
ss.insert2(bigo,num,name,kor,eng,mat,sci,tech,mus);
return "redirect:in";
}
@RequestMapping(value="out")
public String ko5(Model mo) {
Service ss = sqlsession.getMapper(Service.class);
ArrayList<ScoreDTO> list = ss.out();
mo.addAttribute("list", list);
return "output";
}
@RequestMapping(value="delete1")
public String ko6(HttpServletRequest request) {
String dname = request.getParameter("name");
Service ss = sqlsession.getMapper(Service.class);
ss.delete1(dname);
return "redirect:out";
}
@RequestMapping(value="delete2")
public String ko7(HttpServletRequest request) {
String dname = request.getParameter("name");
Service ss = sqlsession.getMapper(Service.class);
ss.delete2(dname);
return "redirect:out";
}
@RequestMapping(value="modify1")
public String ko8(HttpServletRequest request,Model mo) {
String mname = request.getParameter("name");
Service ss = sqlsession.getMapper(Service.class);
ArrayList<ScoreDTO> list = ss.modify1(mname);
mo.addAttribute("list", list);
return "modifyform1";
}
@RequestMapping(value="modify3")
public String ko9(HttpServletRequest request) {
String bigo = request.getParameter("bigo");
int num = Integer.parseInt(request.getParameter("num"));
String name = request.getParameter("name");
int kor = Integer.parseInt(request.getParameter("kor"));
int eng = Integer.parseInt(request.getParameter("eng"));
int mat = Integer.parseInt(request.getParameter("mat"));
int sci = Integer.parseInt(request.getParameter("sci"));
Service ss = sqlsession.getMapper(Service.class);
ss.modify3(bigo, num, name, kor, eng, mat, sci);
return "redirect:out";
}
@RequestMapping(value="modify2")
public String ko10(HttpServletRequest request,Model mo) {
String mname = request.getParameter("name");
Service ss = sqlsession.getMapper(Service.class);
ArrayList<ScoreDTO> list = ss.modify2(mname);
mo.addAttribute("list", list);
return "modifyform2";
}
@RequestMapping(value="modify4")
public String ko11(HttpServletRequest request) {
String bigo = request.getParameter("bigo");
int num = Integer.parseInt(request.getParameter("num"));
String name = request.getParameter("name");
int kor = Integer.parseInt(request.getParameter("kor"));
int eng = Integer.parseInt(request.getParameter("eng"));
int mat = Integer.parseInt(request.getParameter("mat"));
int sci = Integer.parseInt(request.getParameter("sci"));
int tech = Integer.parseInt(request.getParameter("tech"));
int mus = Integer.parseInt(request.getParameter("mus"));
Service ss = sqlsession.getMapper(Service.class);
ss.modify4(bigo, num, name, kor, eng, mat, sci, tech, mus);
return "redirect:out";
}
@RequestMapping(value="/search")
public String ko13() {
return "searchform";
}
@RequestMapping(value="search2")
public String ko14(HttpServletRequest request,Model mo) {
String item = request.getParameter("item");
String value = request.getParameter("value");
Service ss = sqlsession.getMapper(Service.class);
ArrayList<ScoreDTO> list = ss.search2(value);
mo.addAttribute("list", list);
return "output";
}
}
'SPRING' 카테고리의 다른 글
230302_Tiles (0) | 2023.03.02 |
---|---|
230228_Tiles (0) | 2023.02.28 |
230224_MyBatis (0) | 2023.02.24 |
230223_MyBatis (0) | 2023.02.23 |
230222_기본 (0) | 2023.02.22 |
댓글