<%@ 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>
</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="save">
아이디:<input type="text" name="id"><br>
비밀번호:<input type="password" name="pw"><br>
이름:<input type="text" name="name"><br>
전화번호:<input type="text" name="phone"><br>
근무점수:<input type="text" name="jum"><br>
<input type="submit" value="전송"><br>
</form>
</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>
<table border="1" align="center">
<tr>
<th>아이디</th><th>비밀번호</th><th>이름</th>
<th>전화번호</th><th>점수</th><th>수정</th>
</tr>
<c:forEach items="${list}" var="list">
<tr>
<c:url value="delete" var="url">
<c:param name="id" value="${list.id}"/>
</c:url>
<td><a href="${url}">${list.id}</a></td>
<td>${list.pw}</td><td>${list.name}</td>
<td>${list.phone}</td><td>${list.jum}</td>
<td><a href="modify?id=${list.id}">수정</a></td>
</tr>
</c:forEach>
</table>
</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>
<form action="modify2" method="post">
<table border="1" align="center">
<c:forEach items ="${list}" var="list">
<tr>
<th>아이디</th>
<td><input type="text" name="id" value="${list.id}" readonly></td>
</tr>
<tr>
<th>비밀번호</th>
<td><input type="text" name="pw" value="${list.pw}"></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name" value="${list.name}"></td>
</tr>
<tr>
<th>전화번호</th>
<td><input type="text" name="phone" value="${list.phone}"></td>
</tr>
<tr>
<th>점수</th>
<td><input type="text" name="jum" value="${list.jum}"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="수정">
<input type="reset" value="초기화">
</td>
</tr>
</c:forEach>
</table>
</form>
</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);
}
<?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
</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>
</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;
@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";
}
}
<%@ 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>
</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="save",method="get">
<table border="1" align="center">
<tr>
<th>반</th>
<td><input type="text" name="ban"></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>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="초기화">
</td>
</tr>
</table>
</form>
<div align="center"><a href ="/kim5_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"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!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>
<table border="1" align="center" width="800px">
<tr>
<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.ban}</td><td>${list.num}</td><td>${list.name}</td>
<td>${list.kor}</td><td>${list.eng}</td><td>${list.mat}</td>
<td>${list.kor+list.eng+list.mat}</td>
<td><fmt:formatNumber value="${(list.kor+list.eng+list.mat)/3}" pattern="#,##0.0"></fmt:formatNumber></td>
<td>
<a href="delete?name=${list.name}">❌</a>
<a href="modify?name=${list.name}">✅</a>
</td>
</c:forEach>
</tr>
</table>
<div align="center"><a href ="/kim5_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"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="modify2",method="get">
<table border="1" align="center">
<c:forEach items="${list}" var="list">
<tr>
<th>반</th>
<td><input type="text" name="ban" value="${list.ban}"></td>
</tr>
<tr>
<th>번호</th>
<td><input type="text" name="num" value="${list.num}"></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>
<td colspan="2" align="center">
<input type="submit" value="수정">
<input type="reset" value="초기화">
</td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>
package com.ezen.kim5_002;
public class ScoreDTO {
int ban,num;
String name;
int kor,eng,mat;
public ScoreDTO() {
}
public ScoreDTO(int ban, int num, String name, int kor, int eng, int mat) {
super();
this.ban = ban;
this.num = num;
this.name = name;
this.kor = kor;
this.eng = eng;
this.mat = mat;
}
public int getBan() {
return ban;
}
public void setBan(int ban) {
this.ban = ban;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
this.kor = kor;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMat() {
return mat;
}
public void setMat(int mat) {
this.mat = mat;
}
}
package com.ezen.kim5_002;
import java.util.ArrayList;
public interface Service {
public void insert(int ban,int num,String name,int kor,int eng,int mat);
public ArrayList<ScoreDTO> out();
public void delete(String dname);
public ArrayList<ScoreDTO> modify(String mname);
public void modify2(int ban,int num,String name,int kor,int eng,int mat);
}
<?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_002.Service">
<insert id="insert" >
insert into db02242 values (#{param1},#{param2},#{param3},#{param4},#{param5},#{param6})
</insert>
<select id="out" resultType="com.ezen.kim5_002.ScoreDTO">
select * from db02242 order by ban,num asc
</select>
<delete id="delete">
delete from db02242 where name=#{param1}
</delete>
<select id="modify" resultType="com.ezen.kim5_002.ScoreDTO">
select * from db02242 where name=#{param1}
</select>
<update id="modify2">
update db02242 set ban=#{param1},num=#{param2},kor=#{param4},eng=#{param5},mat=#{param6} where name=#{param3}
</update>
</mapper>
package com.ezen.kim5_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="/save")
public String ko3(HttpServletRequest request) {
int ban = Integer.parseInt(request.getParameter("ban"));
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"));
Service ss = sqlsession.getMapper(Service.class);
ss.insert(ban,num,name,kor,eng,mat);
return "redirect:in";
}
@RequestMapping(value="/out")
public String ko4(Model mo) {
Service ss = sqlsession.getMapper(Service.class);
ArrayList<ScoreDTO> list = ss.out();
mo.addAttribute("list", list);
return "output";
}
@RequestMapping(value="/delete")
public String ko4(HttpServletRequest request) {
String dname = request.getParameter("name");
Service ss = sqlsession.getMapper(Service.class);
ss.delete(dname);
return "redirect:out";
}
@RequestMapping(value="/modify")
public String ko5(HttpServletRequest request,Model mo) {
String mname = request.getParameter("name");
Service ss = sqlsession.getMapper(Service.class);
ArrayList<ScoreDTO> list = ss.modify(mname);
mo.addAttribute("list", list);
return "out2";
}
@RequestMapping(value="/modify2")
public String ko6(HttpServletRequest request) {
int ban = Integer.parseInt(request.getParameter("ban"));
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"));
Service ss = sqlsession.getMapper(Service.class);
ss.modify2(ban,num,name,kor,eng,mat);
return "redirect:out";
}
}
'SPRING' 카테고리의 다른 글
230228_Tiles (0) | 2023.02.28 |
---|---|
230227_MyBatis (0) | 2023.02.27 |
230223_MyBatis (0) | 2023.02.23 |
230222_기본 (0) | 2023.02.22 |
230221_기본 (0) | 2023.02.21 |
댓글