본문 바로가기
SPRING

230307_Tiles

by 경 훈 2023. 3. 7.

decode = if 문과 유사

 

<%@ 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>
<header>
<h1 align="center">
스프링 예제 프로그램
</h1>
</header>
</header>
<nav class="navbar navbar-inverse">
	<div class="container-fluid">
	<div class="navbar-header">
		<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>                        
		</button>
	<a class="navbar-brand" href="/kim11_001/">HOME</a>
	</div>
	<div class="collapse navbar-collapse" id="myNavbar">
	<ul class="nav navbar-nav">
		<li class="active">
		</li>
		<li class="dropdown">
		<a class="dropdown-toggle" data-toggle="dropdown" href="#">성적<span class="caret"></span></a>
			<ul class="dropdown-menu">
				<li><a href="scorein">성적입력</a></li>
				<li><a href="schoolin">인적사항입력</a></li>
				<li><a href="scoreout">출력</a></li>
			</ul>
		</li>
		<li class="dropdown">
		<a class="dropdown-toggle" data-toggle="dropdown" href="#">사원자료<span class="caret"></span></a>
			<ul class="dropdown-menu">
				<li><a href="sawoninput">사원입력</a></li>
				<li><a href="sawonout">사원출력</a></li>
				<li><a href="sawoninput2">사원입력2</a></li>
				<li><a href="sawonout2">사원출력2</a></li>
				<li><a href="juminin">주민입력</a></li>
				<li><a href="juminout">주민출력</a></li>
			</ul>
		</li>
	</ul>
	<ul class="nav navbar-nav navbar-right">
		<li><a href="mem"><span class="glyphicon glyphicon-user"></span>회원가입</a></li>
		<li><a href="login"><span class="glyphicon glyphicon-log-in"></span>로그인</a></li>
	</ul>
	</div>
	</div>
</nav>
</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>
	<h3 align="center">성적입력</h3>
	<form action="scoresave">
		<table border="1" align="center">
			<tr>
				<th>번호</th>
				<td><input type="text" name="num"></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="radio" name="gender" value="남자">남자
					<input type="radio" name="gender" value="여자">여자
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="전송">
					<input type="reset" value="리셋">
				</td>
			</tr>
		</table>
	</form>
</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>
	<h3 align="center">인적사항입력</h3>
	<form action="schoolsave">
		<table border="1" align="center">
			<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="phone"></td>
			</tr>
			<tr>
				<th>주소</th>
				<td><input type="text" name="address"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="전송">
					<input type="reset" value="리셋">
				</td>
			</tr>
		</table>
	</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" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3 align="center">출력</h3>
	<table border="1" align="center" width="600px">
		<tr>
			<th>번호</th><th>이름</th><th>총점</th>
			<th>연락처</th><th>성별</th>
		</tr>
		<c:forEach items="${list}" var="list">
		<tr>
			<td>${list.num}</td><td>${list.schooldto.name}</td><td>${list.tot}</td>
			<td>${list.schooldto.phone}</td><td>${list.gender}</td>
		</tr>
		</c:forEach>
	</table>
</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>
	<h3 align="center">사원입력</h3>
	<form action="sawonsave">
		<table border="1" align="center">
			<tr>
				<th>이름</th>
				<td><input type="text" name="name"></td>
			</tr>
			<tr>
				<th>호봉</th>
				<td>
					<select name ="hobong">
						<option value="1">1
						<option value="2">2
						<option value="3">3
						<option value="4">4
						<option value="5">5
					</select>
				</td>
			</tr>
			<tr>
				<th>가족수</th>
				<td>
					<select name ="family">
						<option value="1">1
						<option value="2">2
						<option value="3">3
						<option value="4">4
						<option value="5">5
					</select>
				</td>
			</tr>
			<tr>
				<th>직위</th>
				<td>
					<select name ="grade">
						<option value="이사">이사
						<option value="부장">부장
						<option value="과장">과장
						<option value="대리">대리
						<option value="사원">사원
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="전송">
					<input type="reset" value="리셋">
				</td>
			</tr>
		</table>
	</form>
</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>
	<h3 align="center">사원입력</h3>
	<form action="sawonsave2">
		<table border="1" align="center">
			<tr>
				<th>이름</th>
				<td><input type="text" name="name"></td>
			</tr>
			<tr>
				<th>입사날짜</th>
				<td><input type="date" name="ipsaday"></td>
			</tr>
			<tr>
				<th>기준날짜</th>
				<td><input type="date" name="baseday"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="전송">
					<input type="reset" value="리셋">
				</td>
			</tr>
		</table>
	</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" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ 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>
	<h3 align="center">출력</h3>
	<table border="1" align="center" width="600px">
		<tr>
			<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.name}</td><td>${list.grade}</td><td>${list.hobong}</td><td>${list.family}</td>
			<td><fmt:formatNumber value="${list.gsudang}" pattern="#,##0"/></td>
			<td><fmt:formatNumber value="${list.kibon}" pattern="#,##0"/></td>
			<td><fmt:formatNumber value="${list.fsudang}" pattern="#,##0"/></td>
			<td><fmt:formatNumber value="${list.kibon+list.fsudang+list.gsudang}" pattern="#,##0"/></td>
		</tr>
		</c:forEach> --%>
		<c:forEach var="i" begin="0" end="${fn:length(list)-1}" step="1">
		<tr>
			<td>${list[i].name}</td><td>${list[i].grade}</td><td>${list[i].hobong}</td><td>${list[i].family}</td>
			<td><fmt:formatNumber value="${list[i].gsudang}" pattern="#,##0"/></td>
			<td><fmt:formatNumber value="${list[i].kibon}" pattern="#,##0"/></td>
			<td><fmt:formatNumber value="${list[i].fsudang}" pattern="#,##0"/></td>
			<td><fmt:formatNumber value="${list[i].kibon+list[i].fsudang+list[i].gsudang}" pattern="#,##0"/></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" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ 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>
	<h3 align="center">출력</h3>
	<table border="1" align="center" width="600px">
		<tr>
			<th>이름</th><th>입사일</th><th>기준일</th><th>기본급</th>
		</tr>
		<c:forEach items="${list}" var="list">
		<tr>
			<td>${list.name}</td>
			<td>${list.ipsaday}</td>
			<td>${list.baseday}</td>
			<td><fmt:formatNumber value="${list.kibon}" pattern="#,##0"/></td>
		</tr>
		</c:forEach>
	</table>
</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>
	<h3 align="center">주민입력</h3>
	<form action="juminsave">
		<table border="1" align="center">
			<tr>
				<th>이름</th>
				<td><input type="text" name="name"></td>
			</tr>
			<tr>
				<th>주민번호</th>
				<td><input type="text" name="jumin"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="전송">
					<input type="reset" value="리셋">
				</td>
			</tr>
		</table>
	</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" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3 align="center">출력</h3>
	<table border="1" align="center" width="600px">
		<tr>
			<th>이름</th><th>주민번호</th><th>나이</th><th>비고</th>
		</tr>
		<c:forEach items="${list}" var="list">
		<tr>
			<td>${list.name}</td><td>${list.jumin}</td><td>${list.age}</td>
			<td>${list.bigo}</td>
		</tr>
		</c:forEach>
	</table>
</body>
</html>

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
	<definition name="baseLayout" template="/WEB-INF/views/layout.jsp">
		<put-attribute name="title" value=""/>
		<put-attribute name="top" value="/WEB-INF/views/top.jsp"/>
		<put-attribute name="body" value=""/>
		<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"/>
	</definition>	   
	<definition name="main" extends="baseLayout">
		<put-attribute name="title" value="메인화면"/>
		<put-attribute name="body" value="/WEB-INF/views/main.jsp"/>
	</definition>  
	<definition name="input" extends="baseLayout">
		<put-attribute name="title" value="입력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/input.jsp"/>
	</definition>  
	<definition name="schoolinput" extends="baseLayout">
		<put-attribute name="title" value="인적사항입력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/schoolinput.jsp"/>
	</definition>  
	<definition name="output" extends="baseLayout">
		<put-attribute name="title" value="출력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/output.jsp"/>
	</definition>  
	<definition name="sawoninput" extends="baseLayout">
		<put-attribute name="title" value="사원입력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/sawoninput.jsp"/>
	</definition>  
	<definition name="sawonoutput" extends="baseLayout">
		<put-attribute name="title" value="사원출력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/sawonoutput.jsp"/>
	</definition>  
	<definition name="sawoninput2" extends="baseLayout">
		<put-attribute name="title" value="사원입력폼2"/>
		<put-attribute name="body" value="/WEB-INF/views/sawoninput2.jsp"/>
	</definition>  
	<definition name="sawonoutput2" extends="baseLayout">
		<put-attribute name="title" value="사원출력폼2"/>
		<put-attribute name="body" value="/WEB-INF/views/sawonoutput2.jsp"/>
	</definition>  
	<definition name="jumininput" extends="baseLayout">
		<put-attribute name="title" value="주민입력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/jumininput.jsp"/>
	</definition>  
	<definition name="juminoutput" extends="baseLayout">
		<put-attribute name="title" value="주민출력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/juminoutput.jsp"/>
	</definition>  
</tiles-definitions>

package com.ezen.kim11_001.score;

public class SchoolDTO {
	int num;
	String name,phone,address;
	public SchoolDTO() {
	}
	public SchoolDTO(int num, String name, String phone, String address) {
		super();
		this.num = num;
		this.name = name;
		this.phone = phone;
		this.address = address;
	}
	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 String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
}

 

package com.ezen.kim11_001.score;

public class ScoreDTO {
	int num,kor,eng,mat,tot;
	String gender;
	SchoolDTO schooldto;
	public ScoreDTO() {
	}
	public ScoreDTO(int num, int kor, int eng, int mat, int tot, String gender) {
		super();
		this.num = num;
		this.kor = kor;
		this.eng = eng;
		this.mat = mat;
		this.tot = tot;
		this.gender = gender;
	}
	public int getNum() {
		return num;
	}
	public void setNum(int num) {
		this.num = num;
	}
	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;
	}
	public int getTot() {
		return tot;
	}
	public void setTot(int tot) {
		this.tot = tot;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public SchoolDTO getSchooldto() {
		return schooldto;
	}
	public void setSchooldto(SchoolDTO schooldto) {
		this.schooldto = schooldto;
	}
}

 

package com.ezen.kim11_001.score;

import java.util.ArrayList;

public interface Service1 {
	public void insert(int num,int kor,int eng,int mat,String gender);
	public void insert2(int num,String name,String phone,String address);
	public ArrayList<ScoreDTO> out();
}

 

<?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.kim11_001.score.Service1">
	<insert id="insert">
		insert into score307 values (#{param1},#{param2},#{param3},#{param4},#{param5})
	</insert>
	<insert id="insert2">
		insert into school307 values (#{param1},#{param2},#{param3},#{param4})
	</insert>
	<resultMap type="com.ezen.kim11_001.score.SchoolDTO" id="school">
		<result property="num" column="num"/>
		<result property="name" column="name"/>
		<result property="phone" column="phone"/>
		<result property="address" column="address"/>
	</resultMap>
	<resultMap type="com.ezen.kim11_001.score.ScoreDTO" id="score">
		<result property="num" column="num"/>
		<result property="kor" column="kor"/>
		<result property="eng" column="eng"/>
		<result property="mat" column="mat"/>
		<result property="tot" column="tot"/>
		<result property="gender" column="gender"/>
		<collection property="schooldto" resultMap="school"></collection>
	</resultMap>
	<select id="out" resultMap="score">
		select num,name,(kor+eng+mat) as tot,phone,gender
		from school307 join score307 
		Using (num)
	</select>
</mapper>

 

package com.ezen.kim11_001.score;


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 ScoreController {
	@Autowired
	SqlSession sqlsession;
	@RequestMapping(value="/scorein")
	public String ko1() {
		return "input";
	}
	@RequestMapping(value="/schoolin")
	public String ko5() {
		return "schoolinput";
	}
	@RequestMapping(value="/scoresave")
	public String ko2(HttpServletRequest request) {
		int num = Integer.parseInt(request.getParameter("num"));
		int kor = Integer.parseInt(request.getParameter("kor"));
		int eng = Integer.parseInt(request.getParameter("eng"));
		int mat = Integer.parseInt(request.getParameter("mat"));
		String gender = request.getParameter("gender");
		Service1 ss1 = sqlsession.getMapper(Service1.class);
		ss1.insert(num,kor,eng,mat,gender);
		return "redirect:scorein";
	}
	@RequestMapping(value="/schoolsave")
	public String ko3(HttpServletRequest request) {
		int num = Integer.parseInt(request.getParameter("num"));
		String name = request.getParameter("name");
		String phone = request.getParameter("phone");
		String address = request.getParameter("address");
		Service1 ss1 = sqlsession.getMapper(Service1.class);
		ss1.insert2(num, name, phone, address);
		return "redirect:schoolin";
	}
	
	@RequestMapping(value="/scoreout")
	public String ko4(Model mo) {
		Service1 ss1 = sqlsession.getMapper(Service1.class);
		ArrayList<ScoreDTO> list = ss1.out();
		mo.addAttribute("list", list);
		return "output";
	}
}

package com.ezen.kim11_001.sawon;

public class SawonDTO {
	String name;
	int hobong,family;
	String grade;
	int kibon,fsudang,gsudang;
	public SawonDTO() {
	}
	public SawonDTO(String name, int hobong, int family, String grade, int kibon, int fsudang, int gsudang) {
		super();
		this.name = name;
		this.hobong = hobong;
		this.family = family;
		this.grade = grade;
		this.kibon = kibon;
		this.fsudang = fsudang;
		this.gsudang = gsudang;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getHobong() {
		return hobong;
	}
	public void setHobong(int hobong) {
		this.hobong = hobong;
	}
	public int getFamily() {
		return family;
	}
	public void setFamily(int family) {
		this.family = family;
	}
	public String getGrade() {
		return grade;
	}
	public void setGrade(String grade) {
		this.grade = grade;
	}
	public int getKibon() {
		return kibon;
	}
	public void setKibon(int kibon) {
		this.kibon = kibon;
	}
	public int getFsudang() {
		return fsudang;
	}
	public void setFsudang(int fsudang) {
		this.fsudang = fsudang;
	}
	public int getGsudang() {
		return gsudang;
	}
	public void setGsudang(int gsudang) {
		this.gsudang = gsudang;
	}
}

 

package com.ezen.kim11_001.sawon;

public class SawonDTO2 {
	String name,ipsaday,baseday;
	int kibon;
	public SawonDTO2() {
	}
	public SawonDTO2(String name, String ipsaday, String baseday, int kibon) {
		super();
		this.name = name;
		this.ipsaday = ipsaday;
		this.baseday = baseday;
		this.kibon = kibon;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getIpsaday() {
		return ipsaday;
	}
	public void setIpsaday(String ipsaday) {
		this.ipsaday = ipsaday;
	}
	public String getBaseday() {
		return baseday;
	}
	public void setBaseday(String baseday) {
		this.baseday = baseday;
	}
	public int getKibon() {
		return kibon;
	}
	public void setKibon(int kibon) {
		this.kibon = kibon;
	}
}

 

package com.ezen.kim11_001.sawon;

public class JuminDTO {
	String name,jumin;
	int age;
	String bigo;
	public JuminDTO() {
	}
	public JuminDTO(String name, String jumin, int age) {
		super();
		this.name = name;
		this.jumin = jumin;
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getJumin() {
		return jumin;
	}
	public void setJumin(String jumin) {
		this.jumin = jumin;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getBigo() {
		return bigo;
	}
	public void setBigo(String bigo) {
		this.bigo = bigo;
	}
	
}

 

package com.ezen.kim11_001.sawon;

import java.util.ArrayList;

public interface Service2 {
	public void insert(String name,int hobong,int family,String grade);
	public ArrayList<SawonDTO> out();
	public void insert2(String name,String ipsaday,String baseday);
	public ArrayList<SawonDTO2> out2();
	public void insert3(String name,String jumin,int age);
	public ArrayList<JuminDTO> out3();
}

 

<?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.kim11_001.sawon.Service2">
	<insert id="insert">
		insert into sawon307 values (#{param1},#{param2},#{param3},#{param4})
	</insert>
	<select id="out" resultType="com.ezen.kim11_001.sawon.SawonDTO">
		select name,hobong,family,grade,
		(decode(hobong,1,1000000,
					   2,2000000,
					   3,3000000,
					   4,4000000,
					     5000000)) as kibon,
		(decode(family,1,100000,
					   2,200000,
					   3,300000,
					   4,400000,
					     500000)) as fsudang,
		(case grade when '이사' then 7000000 
					when '부장' then 5000000 
					when '과장' then 4000000 
					when '대리' then 3000000 
					when '사원' then 2000000 
					end
		) as gsudang from sawon307
	</select>
	<insert id="insert2">
		insert into sawon3072 values (#{param1},#{param2},#{param3})
	</insert>
	<select id="out2" resultType="com.ezen.kim11_001.sawon.SawonDTO2">
		select name,ipsaday,baseday,
		(decode(trunc(MONTHS_BETWEEN(baseday,ipsaday)/12)+1,
		1,1000000,
		2,2000000,
		3,3000000,
		4,4000000,
		5,5000000,
		  7000000
        )) as kibon from sawon3072
	</select>
	<insert id="insert3">
		insert into db03071 values (#{param1},#{param2},#{param3})
	</insert>
	<select id="out3" resultType="com.ezen.kim11_001.sawon.JuminDTO">
		select name,jumin,age,
        (decode(trunc(age/10),
        0,'어린이',
        1,'청소년학생',
        2,'청년',
        3,'청년',
        4,'중년',
        5,'중년',
        6,'장년',
        '어르신')) as bigo from db03071
	</select>
</mapper>

 

package com.ezen.kim11_001.sawon;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;

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.servlet.ModelAndView;

@Controller
public class SawonController {
	@Autowired
	SqlSession sqlsession;
	@RequestMapping(value="/sawoninput")
	public String ko1() {
		return "sawoninput";
	}
	@RequestMapping(value="/sawonsave")
	public String ko2(HttpServletRequest request) {
		String name = request.getParameter("name");
		int hobong = Integer.parseInt(request.getParameter("hobong"));
		int family = Integer.parseInt(request.getParameter("family"));
		String grade = request.getParameter("grade");
		Service2 ss2 = sqlsession.getMapper(Service2.class);
		ss2.insert(name,hobong,family,grade);
		return "redirect:sawoninput";
	}
	@RequestMapping(value="/sawonout")
	public String ko3(Model mo) {
		Service2 ss2 = sqlsession.getMapper(Service2.class);
		ArrayList<SawonDTO> list = ss2.out();
		mo.addAttribute("list", list);
		return "sawonoutput";
	}
	@RequestMapping(value="/sawoninput2")
	public String ko4() {
		return "sawoninput2";
	}
	@RequestMapping(value="/sawonsave2")
	public String ko5(HttpServletRequest request) {
		String name = request.getParameter("name");
		String ipsaday = request.getParameter("ipsaday");
		String baseday = request.getParameter("baseday");
		Service2 ss2 = sqlsession.getMapper(Service2.class);
		ss2.insert2(name,ipsaday,baseday);
		return "redirect:sawoninput2";
	}
	@RequestMapping(value="/sawonout2")
	public String ko6(Model mo) {
		Service2 ss2 = sqlsession.getMapper(Service2.class);
		ArrayList<SawonDTO2> list = ss2.out2();
		mo.addAttribute("list", list);
		return "sawonoutput2";
	}
	@RequestMapping(value="/juminin")
	public String ko7() {
		return "jumininput";
	}
	@RequestMapping(value="/juminsave")
	public String ko8(HttpServletRequest request) {
		String name = request.getParameter("name");
		String jumin = request.getParameter("jumin");
		int check = Integer.parseInt(jumin.substring(7, 8));
		int juminday = 0;
		if(check==1 ||check==2) {
			juminday = Integer.parseInt(jumin.substring(0, 2))+1900;
		}
		else {
			juminday = Integer.parseInt(jumin.substring(0, 2))+2000;
		}
		GregorianCalendar gc = new GregorianCalendar();
		int nowyear = gc.get(Calendar.YEAR);
		int age = nowyear-juminday+1;
		Service2 ss2 = sqlsession.getMapper(Service2.class);
		ss2.insert3(name,jumin,age);
		return "redirect:juminin";
	}
//	@RequestMapping(value="/juminout")
//	public String ko9(Model mo) {
//		Service2 ss2 = sqlsession.getMapper(Service2.class);
//		ArrayList<JuminDTO> list = ss2.out3();
//		mo.addAttribute("list", list);
//		return "juminoutput";
//	}
	@RequestMapping(value="/juminout")
	public ModelAndView ko9() {
		ModelAndView mav = new ModelAndView();
		Service2 ss2 = sqlsession.getMapper(Service2.class);
		ArrayList<JuminDTO> list = ss2.out3();
		mav.addObject("list", list);
		mav.setViewName("juminoutput");
		return mav;
	}
}

 

'SPRING' 카테고리의 다른 글

230309_AJAX  (0) 2023.03.09
230308_AJAX  (0) 2023.03.08
230306_Tiles  (0) 2023.03.06
230303_Tiles  (0) 2023.03.03
230302_Tiles  (0) 2023.03.02

댓글