본문 바로가기
IT/MyBatis

[MyBatis]

by dya0 2019. 6. 19.

date.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form action="<%=request.getContextPath()%>/term2.net" method ="post">
    <label>조회기간</label><br>
    <input type="date" name="startday" min="1980-01-01" max="1987-12-31" >
    ~
    <input type="date" name="endday" min="1980-01-01" max="1987-12-31" >
    <input type="submit" value="검색"/>
 
</form>
</body>
</html>
 

emplist.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>사원조회</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
<script
<script
 
</head>
<body>
    <script>
        console.log("${emp}");
    </script>
    <div class="container">
        <c:if test="${emp.size() > 0 }">
            <table class="table">
                <thead>
                    <tr>
                        <th>이름</th>
                        <th>사원번호</th>
                        <th>직업</th>
                        <th>입사일</th>
                        <th>부서번호</th>
                    </tr>
                </thead>
                <tbody>
 
                    <c:forEach var="l" items="${emp}">
 
                        <tr>
                            <td>${l.ename }</td>
                            <td>${l.empno }</td>
                            <td>${l.job }</td>
                            <td>${l.hiredate }</td>
                            <td>${l.deptno }</td>
 
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </c:if>
        <c:if test="${emp.size() == 0 }">
        <h1>조회 결과가 없습니다.</h1>
        </c:if>
    </div>
</body>
</html>
 

term2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package jsp;
 
 
 
import dao.EmpDao;
import model.Employee;
 
public class Term2 implements Action {
 
    @Override
    public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        EmpDao dao = new EmpDao();
        Map<String, String> m = new HashMap<>();
        Employee emp = new Employee();
        m.put("startday", request.getParameter("startday"));
        m.put("endday", request.getParameter("endday"));
        System.out.println("term2action");
        List <Employee> list= new ArrayList<Employee>();
 
        list = dao.getList2(m);
        ActionForward forward = new ActionForward();
        forward.setPath("question2/emplist.jsp");
        request.setAttribute("emp", list);
        return forward;
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

term3

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package jsp;
 
 
 
import dao.EmpDao;
import model.Employee;
 
public class Term3 implements Action {
 
    @Override
    public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        EmpDao dao = new EmpDao();
        Map<StringString> m = new HashMap<>();
        Employee emp = new Employee();
        m.put("startday", request.getParameter("startday"));
        m.put("endday", request.getParameter("endday"));
        String deptno = request.getParameter("deptno");
        System.out.println("deptno  = " + deptno);
        m.put("deptno", deptno);
        System.out.println("term2action");
        List <Employee> list= new ArrayList<Employee>();
 
        list = dao.getList3(m);
        ActionForward forward = new ActionForward();
        forward.setPath("question2/emplist.jsp");
        request.setAttribute("emp", list);
        return forward;
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
<mapper namespace="Member1">
 
    <select id="select" parameterType="String" resultType="Member">
        select *
        from member22 where id =#{inputid}
    </select>
    <insert id="insert" parameterType="Member">
        insert into member22 values
        (#{id}, #{password})
    </insert>
 
    <select id="listAll" parameterType="Member" resultType="Member">
        select *
        from member22
    </select>
    <select id="list" parameterType="Member" resultType="Map">
        select *
        from member22
    </select>
    <update id="modify" parameterType="Member">
        update member22 set
        password=#{password} where id=#{id}
    </update>
    <delete id="delete" parameterType="String">
        delete from member22 where
        id=#{id}
    </delete>
    <select id="selectdate" parameterType="model.date"
        resultType="model.Employee">
        select * from emp
        where hiredate between #{startday} and
        #{endday}
    </select>
    <select id="termlist" parameterType="map"
        resultType="model.Employee">
        select * from emp
        where hiredate between #{startday} and
        #{endday}
    </select>
    <select id="termlist2" parameterType="map"
        resultType="model.Employee">
 
        select * from emp
        <where>
            <if test='startday!="" and endday !=""'>
                hiredate between #{startday} and #{endday}
            </if>
        </where>
 
    </select>
    <select id="termlist3" parameterType="map"
        resultType="model.Employee">
        <!-- where 요소는 조건에 따라 where을 추가한다. where 다음에 and나 or로 시작하면 삭제한다. -->
        select * from emp
        <where>
            <if test='startday!="" and endday !=""'>
                hiredate between #{startday} and #{endday}
            </if>
            <if test='deptno != ""'>
                and deptno = #{deptno}
            </if>
        </where>
 
    </select>
 
    <select id="checklist1" parameterType="String"
        resultType="model.Employee">
        select * from emp
        <where>
        <!-- array객체 갯수가 없으면 null -->
            <if test='array!= null'>
            deptno IN
                <foreach collection="array" item="deptno" open="(" close=")" separator=",">
                      #{deptno}
                </foreach>
            </if>
 
        </where>
        order by deptno
 
    </select>
</mapper>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

'IT > MyBatis' 카테고리의 다른 글

[MyBatis] 조인  (1) 2019.06.20
[MyBatis] 마이바티스 날짜 조건으로 조회  (1) 2019.06.19
[MyBatis] DB 연결  (0) 2019.06.17
[MyBatis]  (0) 2019.06.17