이안의 평일코딩

Spring 12일차 - PL/SQL Procedure 게시판 만들기 본문

Back-end/Spring

Spring 12일차 - PL/SQL Procedure 게시판 만들기

이안92 2020. 11. 12. 10:57
반응형

2020.11.12(목)

SpringProcedureProject1

pom.xml, web.xml 복붙

WEB-INF/에 config폴더 생성후

Bean으로 application-context.xml 생성(beans, context(component-scan), p)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    <context:component-scan base-package="com.sist.*"></context:component-scan>
    <!-- JSP 찾기 -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/main/"
        p:suffix=".jsp"
    />
</beans>
 
cs

 

pom.xml에 ojdbc14.jar 설치 (WEB-INF/lib폴더에 ojdbc14.jar 다운받아서 넣은 뒤에)

1
2
3
4
5
6
7
8
9
10
11
12
<!--  <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14</artifactId>
            <version>10.2.0.4.0</version>
        </dependency> -->
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14</artifactId>
            <version>10.2.0.4.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/ojdbc14.jar</systemPath>
        </dependency>
cs

 

src/main/java

com.sist.dao

StudentVO

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
package com.sist.dao;
// 사용자 정의 데이터형 
public class StudentVO {
    private int hakbun;
    private String name;
    private int kor;
    private int eng;
    private int math;
    private int total;
    private double avg;
    public int getHakbun() {
        return hakbun;
    }
    public void setHakbun(int hakbun) {
        this.hakbun = hakbun;
    }
    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 getMath() {
        return math;
    }
    public void setMath(int math) {
        this.math = math;
    }
    public int getTotal() {
        return total;
    }
    public void setTotal(int total) {
        this.total = total;
    }
    public double getAvg() {
        return avg;
    }
    public void setAvg(double avg) {
        this.avg = avg;
    }
    
}
 
cs

 

StudentDAO

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
package com.sist.dao;
 
import org.springframework.stereotype.Repository;
 
import oracle.jdbc.driver.OracleTypes;
 
import java.util.*;
import java.sql.*;
 
@Repository
public class StudentDAO {
    private Connection conn;
    private CallableStatement cs;
    private final String URL="jdbc:oracle:thin:@localhost:1521:XE";
    /*
     * PreparedStatement : 일반 SQL문장 전송
     * CallableStatement : Procedure를 호출
     */
    // 드라이버 등록
    public StudentDAO(){
        try{
            Class.forName("oracle.jdbc.driver.OracleDriver");
        }catch(Exception ex){}
    }
    // 연결
    public void getConnection(){
        try{
            conn=DriverManager.getConnection(URL,"hr","happy");
        }catch(Exception ex){}
    }
    // 해제
    public void disConnection(){
        try{
            if(cs!=null) cs.close();
            if(conn!=null) conn.close();
        }catch(Exception ex){}
    }
    // 기능
    /*
     *  CREATE OR REPLACE PROCEDURE studentListData(
            pResult OUT SYS_REFCURSOR  => 데이터 하나이므로 ? 하나줌
            
        )
        IS
        BEGIN
            OPEN pResult FOR
                SELECT * FROM pl_student;
        END;
     */
    public List<StudentVO> studentListData(){
        List<StudentVO> list=new ArrayList<StudentVO>();
        try{
            getConnection();
            String sql="{CALL studentListData(?)}";
            cs=conn.prepareCall(sql);
            cs.registerOutParameter(1, OracleTypes.CURSOR);
            // int ==> OracleTypes.INTEGER
            // String ==> OracleTypes.VARCHAR
            // double ==> OracleTypes.DOUBLE
            // date ==> OracleTypes.DATE
            // ResultSet ==> OracleTypes.CURSOR
            // 실행
            cs.executeQuery();
            ResultSet rs=(ResultSet)cs.getObject(1);
            while(rs.next()){
                StudentVO vo=new StudentVO();
                vo.setHakbun(rs.getInt(1));
                vo.setName(rs.getString(2));
                vo.setKor(rs.getInt(3));
                vo.setEng(rs.getInt(4));
                vo.setMath(rs.getInt(5));
                list.add(vo);
            }
            rs.close();
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }finally{
            disConnection();
        }
        return list;
    }
}
 
cs

 

com.sist.web

MainController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.sist.web;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
// MVC => Model (요청을 처리 => 결과값을 전송)
import java.util.*;
import com.sist.dao.*;
@Controller
public class MainController {
    // DAO 객체 받기
    @Autowired
    private StudentDAO dao;
    @RequestMapping("main/list.do")
    public String main_list(Model model){
        List<StudentVO> list=dao.studentListData();
        model.addAttribute("list",list);
        return "list";
    }
}
 
cs

src/main/webapp/main

list.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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row{
    margin: 0px auto;
    width:600px;
}
</style>
</head>
<body>
    <div class="container">
        <div class="row">
            <h3 class="text-center">학생정보</h3>
            <table class="table table-striped">
                <tr class="success">
                <th>학번</th>
                <th>이름</th>
                <th>국어</th>
                <th>영어</th>
                <th>수학</th>
                </tr>
                <c:forEach var="vo" items="${list }">
                    <tr>
                        <td>${vo.hakbun }</td>
                        <td>${vo.name }</td>
                        <td>${vo.kor }</td>
                        <td>${vo.eng }</td>
                        <td>${vo.math }</td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
</body>
</html>
cs

PL/SQL 참조

iancoding.tistory.com/110

 

Oracle 20일차 - Cursor, Function

2020.11.11~12(수, 목) -- cursor : 여러개 Row(Record)를 저장할 수 있는 공간 ==> ResultSet -- 처리 => CURSOR => 자바 (ResultSet) 1. 커서등록     cursor cur_name IS       ..

iancoding.tistory.com

 

src/main/java

com.sist.dao

StudentDAO.java

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.sist.dao;
 
import org.springframework.stereotype.Repository;
 
import oracle.jdbc.driver.OracleTypes;
 
import java.util.*;
import java.sql.*;
 
@Repository
public class StudentDAO {
    private Connection conn;
    private CallableStatement cs;
    private final String URL="jdbc:oracle:thin:@localhost:1521:XE";
    /*
     * PreparedStatement : 일반 SQL문장 전송
     * CallableStatement : Procedure를 호출
     */
    // 드라이버 등록
    public StudentDAO(){
        try{
            Class.forName("oracle.jdbc.driver.OracleDriver");
        }catch(Exception ex){}
    }
    // 연결
    public void getConnection(){
        try{
            conn=DriverManager.getConnection(URL,"hr","happy");
        }catch(Exception ex){}
    }
    // 해제
    public void disConnection(){
        try{
            if(cs!=null) cs.close();
            if(conn!=null) conn.close();
        }catch(Exception ex){}
    }
    // 기능
    /*
     *  CREATE OR REPLACE PROCEDURE studentListData(
            pResult OUT SYS_REFCURSOR  => 데이터 하나이므로 ? 하나줌
            
        )
        IS
        BEGIN
            OPEN pResult FOR
                SELECT * FROM pl_student;
        END;
     */
    public List<StudentVO> studentListData(){
        List<StudentVO> list=new ArrayList<StudentVO>();
        try{
            getConnection();
            String sql="{CALL studentListData(?)}";
            cs=conn.prepareCall(sql);
            cs.registerOutParameter(1, OracleTypes.CURSOR);
            // int ==> OracleTypes.INTEGER
            // String ==> OracleTypes.VARCHAR
            // double ==> OracleTypes.DOUBLE
            // date ==> OracleTypes.DATE
            // ResultSet ==> OracleTypes.CURSOR
            // 실행
            cs.executeQuery();
            ResultSet rs=(ResultSet)cs.getObject(1);
            while(rs.next()){
                StudentVO vo=new StudentVO();
                vo.setHakbun(rs.getInt(1));
                vo.setName(rs.getString(2));
                vo.setKor(rs.getInt(3));
                vo.setEng(rs.getInt(4));
                vo.setMath(rs.getInt(5));
                vo.setTotal(rs.getInt(6));
                vo.setAvg(rs.getDouble(7));
                list.add(vo);
            }
            rs.close();
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }finally{
            disConnection();
        }
        return list;
    }
    /*
     CREATE OR REPLACE PROCEDURE studentInsert(
        pName pl_student.name%TYPE,
        pKor pl_student.kor%TYPE,
        pEng pl_student.eng%TYPE,
        pMath pl_student.math%TYPE
    )
    IS
    BEGIN
        INSERT INTO pl_student VALUES(
            (SELECT NVL(MAX(hakbun)+1,1) FROM pl_student),
            pName,pKor,pEng,pMath
        );
        COMMIT;
    END;
    /
     */
    public void studentInsert(StudentVO vo){
        try{
            getConnection();
            String sql="{CALL studentInsert(?,?,?,?)}";
            cs=conn.prepareCall(sql);
            cs.setString(1, vo.getName());
            cs.setInt(2, vo.getKor());
            cs.setInt(3, vo.getEng());
            cs.setInt(4, vo.getMath());
            cs.executeQuery(); //프로시저 실행은 update가 아니라 Query
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }finally{
            disConnection();
        }
    }
    /*
     * CREATE OR REPLACE PROCEDURE studentDelete(
            pNo pl_student.hakbun%TYPE
        )
        IS
        BEGIN
            DELETE FROM pl_student
            WHERE hakbun=pNo;
            COMMIT;
        END;
     */
    public void studentDelete(int hakbun){
        try{
            getConnection();
            String sql="{CALL studentDelete(?)}";
            cs=conn.prepareCall(sql);
            cs.setInt(1, hakbun);
            cs.executeQuery();
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }finally{
            disConnection();
        }
    }
    /*
         CREATE OR REPLACE PROCEDURE studentDetailData(
            pNo NUMBER,
            pName OUT VARCHAR2,
            pKor OUT NUMBER,
            pEng OUT NUMBER,
            pMath OUT NUMBER
        )
        IS
        BEGIN
            SELECT name, kor, eng, math INTO pName, pKor, pEng, pMath
            FROM pl_student
            WHERE hakbun=pNo;
        END;
        /
     */
    // 수정전에 데이터 불러오기 위해서
    public StudentVO studentDetailData(int hakbun){
        StudentVO vo=new StudentVO();
        try{
            getConnection();
            String sql="{CALL studentDetailData(?,?,?,?,?)}";
            cs=conn.prepareCall(sql);
            cs.setInt(1, hakbun);
            cs.registerOutParameter(2, OracleTypes.VARCHAR); //name
            cs.registerOutParameter(3, OracleTypes.INTEGER); //kor
            cs.registerOutParameter(4, OracleTypes.INTEGER); //eng
            cs.registerOutParameter(5, OracleTypes.INTEGER); //math
            cs.executeQuery();
            vo.setName(cs.getString(2));
            vo.setKor(cs.getInt(3));
            vo.setEng(cs.getInt(4));
            vo.setMath(cs.getInt(5));
            vo.setHakbun(hakbun);
            
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }finally{
            disConnection();
        }
        return vo;
    }
    /*
     CREATE OR REPLACE PROCEDURE studentUpdate(
        pNo NUMBER,
        pName VARCHAR2,
        pKor NUMBER,
        pEng NUMBER,
        pMath NUMBER
    )
    IS
     -- 변수
    BEGIN
        UPDATE pl_student SET
        name=pName, kor=pKor, eng=pEng, math=pMath
        WHERE hakbun=pNo;
        COMMIT;
     */
    public void studentUpdate(StudentVO vo){
        try{
            getConnection();
            String sql="{CALL studentUpdate(?,?,?,?,?)}";
            cs=conn.prepareCall(sql);
            cs.setInt(1, vo.getHakbun());
            cs.setString(2, vo.getName());
            cs.setInt(3, vo.getKor());
            cs.setInt(4, vo.getEng());
            cs.setInt(5, vo.getMath());
            cs.executeQuery();
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }finally{
            disConnection();
        }
    }
}
 
cs

 

src/main/java

com.sist.web

MainController

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
package com.sist.web;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
// MVC => Model (요청을 처리 => 결과값을 전송)
import java.util.*;
import com.sist.dao.*;
@Controller
public class MainController {
    // DAO 객체 받기
    @Autowired
    private StudentDAO dao;
    
    @RequestMapping("main/list.do")
    public String main_list(Model model){
        List<StudentVO> list=dao.studentListData();
        model.addAttribute("list",list);
        return "list";
    }
    // ?name=aaa&kor=100&eng=80&math=70
    @RequestMapping("main/insert.do")
    public String main_insert(){
        return "insert";
    }
    
    @RequestMapping("main/insert_ok.do")
    public String main_insert_ok(StudentVO vo){
        dao.studentInsert(vo);
        return "redirect:list.do";
    }
    
    @RequestMapping("main/delete.do")
    public String main_delete(int hakbun){
        dao.studentDelete(hakbun);
        return "redirect:list.do";
    }
    
    @RequestMapping("main/update.do")
    public String main_update(int hakbun, Model model){ //값을 보내주기 위해 Model사용
        StudentVO vo=dao.studentDetailData(hakbun);
        model.addAttribute("vo",vo);
        return "update";
    }
    
    @RequestMapping("main/update_ok.do")
    public String main_update_ok(StudentVO vo){
        dao.studentUpdate(vo);
        return "redirect:list.do";
    }
}
 
cs

 

web.xml

스프링4 -> 스프링5 Annotation 사용위해, XML 읽기 위해

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
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>com.sist.config.AppConfig</param-value>
        </init-param>
        <!-- WebApplicationContext -->
        <!-- application-*.xml 사용할 때
        <init-param>
        <param-name>ContextConfigLocation</param-name>
        <param-value>/WEB-INF/config/application-*.xml</param-value>
        </init-param>
         -->
    </servlet>
    
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <!-- 한글 변환 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
            <init-param>
                <param-name>forceEncoding</param-name>
                <param-value>true</param-value>
            </init-param>
    </filter>
    <!-- /의 형식으로 시작하는 url에 대하여 UTF-8로 인코딩 -->
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
 
cs

 

src/main/java

com.sist.config

AppConfig (application-context.xml을 java형식으로 변경)

implements WebMvcConfigurer - Source - Override/Implement Methods..

 

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
package com.sist.config;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
 
@Configuration
@EnableWebMvc
@ComponentScan(basePackages={"com.sist.*"})
/*
 * DispatcherServlet ==> HandlerMapping (클래스 찾기)
 *                      ==> ViewResolver (JSP찾기)
 */
public class AppConfig implements WebMvcConfigurer {
 
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
    /*
     <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/main/"
        p:suffix=".jsp"
     />
     */
    @Bean
    public ViewResolver viewResolver(){
        InternalResourceViewResolver v=new InternalResourceViewResolver();
        v.setPrefix("/main/");
        v.setSuffix(".jsp");
        return v;
    }
}
 
cs

 

src/main/webapp/main

list.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
57
58
59
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row{
    margin: 0px auto;
    width:600px;
}
</style>
</head>
<body>
    <div class="container">
        <div class="row">
            <h3 class="text-center">학생정보</h3>
            <table class="table">
                <tr>
                 <td>
                  <a href="insert.do" class="btn btn-sm btn-danger">등록</a>
                 </td>
                </tr>
            </table>
            
            <table class="table table-striped">
                <tr class="success">
                    <th>학번</th>
                    <th>이름</th>
                    <th>국어</th>
                    <th>영어</th>
                    <th>수학</th>
                    <th>총점</th>
                    <th>평균</th>
                    <th></th>
                </tr>
                <c:forEach var="vo" items="${list }">
                    <tr>
                        <td>${vo.hakbun }</td>
                        <td>${vo.name }</td>
                        <td>${vo.kor }</td>
                        <td>${vo.eng }</td>
                        <td>${vo.math }</td>
                        <td>${vo.total }</td>
                        <td>${vo.avg }</td>
                        <td>
                         <a href="update.do?hakbun=${vo.hakbun }" class="btn btn-sm btn-success">수정</a>
                         <a href="delete.do?hakbun=${vo.hakbun }" class="btn btn-sm btn-info">삭제</a>
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
</body>
</html>
cs

 

insert.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
57
58
59
<%@ 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>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row{
    margin: 0px auto;
    width:400px;
}
</style>
</head>
<body>
    <div class="container">
        <div class="row">
            <h3 class="text-center">성적등록</h3>
            <form method=post action="insert_ok.do">
            <table class="table">
                <tr>
                    <td width=20% class="text-right success">이름</td>
                    <td width=80%>
                        <input type=text name=name size=15 required> <!-- required는 반드시 입력 -->
                    </td>
                </tr>
                <tr>
                    <td width=20% class="text-right success">국어</td>
                    <td width=80%>
                        <input type=text name=kor size=15 required>
                    </td>
                </tr>
                <tr>
                    <td width=20% class="text-right success">영어</td>
                    <td width=80%>
                        <input type=text name=eng size=15 required>
                    </td>
                </tr>
                <tr>
                    <td width=20% class="text-right success">수학</td>
                    <td width=80%>
                        <input type=text name=math size=15 required>
                    </td>
                </tr>
                <tr>
                    <td class="text-center" colspan="2">
                        <button class="btn btn-sm btn-danger">등록</button>
                        <input type=button class="btn btn-sm btn-danger" value="취소"
                         onclick="javascript:history.back()"
                        >
                    </td>
                </tr>
            </table>
            </form>
        </div>
    </div>
</body>
</html>
cs

 

update.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
57
58
59
60
<%@ 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>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row{
    margin: 0px auto;
    width:400px;
}
</style>
</head>
<body>
    <div class="container">
        <div class="row">
            <h3 class="text-center">성적수정</h3>
            <form method=post action="update_ok.do">
            <table class="table">
                <tr>
                    <td width=20% class="text-right success">이름</td>
                    <td width=80%>
                        <input type=text name=name size=15 required value="${vo.name }">
                        <input type=hidden name=hakbun value="${vo.hakbun }">
                    </td>
                </tr>
                <tr>
                    <td width=20% class="text-right success">국어</td>
                    <td width=80%>
                        <input type=text name=kor size=15 required value="${vo.kor }">
                    </td>
                </tr>
                <tr>
                    <td width=20% class="text-right success">영어</td>
                    <td width=80%>
                        <input type=text name=eng size=15 required value="${vo.eng }">
                    </td>
                </tr>
                <tr>
                    <td width=20% class="text-right success">수학</td>
                    <td width=80%>
                        <input type=text name=math size=15 required value="${vo.math }">
                    </td>
                </tr>
                <tr>
                    <td class="text-center" colspan="2">
                        <button class="btn btn-sm btn-danger">등록</button>
                        <input type=button class="btn btn-sm btn-danger" value="취소"
                         onclick="javascript:history.back()"
                        >
                    </td>
                </tr>
            </table>
            </form>
        </div>
    </div>
</body>
</html>
cs

 

오늘 한줄요약

PL/SQL => DAO에서 처리 => MainController에서 처리 (Annotation) => jsp

반응형

'Back-end > Spring' 카테고리의 다른 글

Spring 14일차 - Tiles  (1) 2020.11.16
Spring 13일차 - Mybatis연동, JSON  (0) 2020.11.13
Spring 11일차 - React  (0) 2020.11.11
Spring 10일차 - 스프링 MVC  (2) 2020.11.09
Spring 8일차 - MyBatis 연동  (0) 2020.11.03
Comments