본문 바로가기

spring/소스코드

학사 프로그램 만들기

 

<학생프로그램>

 

<com.example.domain>-<StudentsVO.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
 
 
public class StudentsVO {
    private String scode;
    private String sname;
    private String dept;
    private String year;
    private Date Birthday;
    private String advisor;
    private String pname;
    public String getScode() {
        return scode;
    }
    public void setScode(String scode) {
        this.scode = scode;
    }
    public String getSname() {
        return sname;
    }
    public void setSname(String sname) {
        this.sname = sname;
    }
    public String getDept() {
        return dept;
    }
    public void setDept(String dept) {
        this.dept = dept;
    }
    public String getYear() {
        return year;
    }
    public void setYear(String year) {
        this.year = year;
    }
    public Date getBirthday() {
        return Birthday;
    }
    public void setBirthday(Date birthday) {
        Birthday = birthday;
    }
    public String getAdvisor() {
        return advisor;
    }
    public void setAdvisor(String advisor) {
        this.advisor = advisor;
    }
    public String getPname() {
        return pname;
    }
    public void setPname(String pname) {
        this.pname = pname;
    }
    @Override
    public String toString() {
        return "StudentsVO [scode=" + scode + ", sname=" + sname + ", dept=" + dept + ", year=" + year + ", Birthday="
                + Birthday + ", advisor=" + advisor + ", pname=" + pname + "]";
    }
    
    
    
    
    
    
    
    
    
}
 
 
 

 

<com.example.persistence>-<StudentsDAO.Imterface>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.example.persistence;
 
 
 
 
public interface StudentsDAO {
    
    
   public List<StudentsVO> list(Criteria cri)throws Exception;
   public int total()throws Exception;
   public void insert(StudentsVO vo) throws Exception;
   
   
   
   
   public StudentsVO read(String scode) throws Exception;
   
   public void update(StudentsVO vo) throws Exception;
   public void delete(String scode) throws Exception;
}
 
 
 

<src/main/resource>-<mappers>-<StudentsMapper.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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
<mapper namespace="StudentsMapper">
 
 
    <select id="list" resultType="com.example.domain.StudentsVO">
       select s.*,pname from students s,professors where advisor=pcode
       limit #{pageStart}, #{perPageNum}
    </select>
    <select id="total" resultType="int">
        select count(*) from students
    </select>
    <insert id="insert">
         insert into students(scode, sname, dept, advisor,birthday,year)
         values (#{scode},#{sname},#{dept},#{advisor},#{birthday},#{year})
    </insert>
    
    
    
    
    
    
    <select id="read" resultType="com.example.domain.StudentsVO">
        select * from students 
        where scode=#{scode}
    </select>
    
    <update id="update">
        update students
        set sname=#{sname},dept=#{dept},year=#{year}
        where scode=#{scode}
    </update>
    <delete id="delete">
        delete from students 
        where scode=#{scode}
    </delete>
</mapper>
 
 

<com.example.persistence>-<StudentsDAOImpl.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
package com.example.persistence;
 
 
 
import org.springframework.stereotype.Repository;
 
 
@Repository
public class StudentsDAOImpl implements StudentsDAO{
    @Inject
    SqlSession session;
    private static final String namespace="StudentsMapper";
    
    @Override
    public List<StudentsVO> list(Criteria cri) throws Exception {
        return session.selectList(namespace+".list", cri);
    }
 
    @Override
    public int total() throws Exception {
        return session.selectOne(namespace+".total");
    }
 
    @Override
    public void insert(StudentsVO vo) throws Exception {
        session.insert(namespace + ".insert",vo);
    }
 
    
    
    
    
    
    
    
    @Override
    public StudentsVO read(String scode) throws Exception {
        return session.selectOne(namespace+".read",scode);
    }
 
    @Override
    public void update(StudentsVO vo) throws Exception {
        // TODO Auto-generated method stub
        session.update(namespace +".update",vo);
    }
 
    @Override
    public void delete(String scode) throws Exception {
        // TODO Auto-generated method stub
        session.delete(namespace +".delete",scode);
    }
 
}
 
 
 

<com.example.controller>-<StudentsController.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
 
 
 
 
import org.springframework.stereotype.Controller;
 
import com.example.persistence.ProfessorsDAO;
import com.example.persistence.StudentsDAO;
 
@Controller
@RequestMapping("/students/*")
public class StudentsController {
       @Inject
       StudentsDAO dao;
       
       @RequestMapping("list")
       public String list(Model model, Criteria cri) throws Exception{
          // System.out.println(cri.toString());
           model.addAttribute("list"dao.list(cri));
           
           PageMaker pm=new PageMaker();
           pm.setCri(cri);
           pm.setTotalCount(dao.total());
           model.addAttribute("pm",pm);
           
           return "/students/list";
       }
       @RequestMapping("insert")
       public String insert(){
           return "/students/insert";
       }
       @RequestMapping(value="insert", method=RequestMethod.POST)
       public String insert(StudentsVO vo,String yy,String mm,String dd) throws Exception{
           String birthday=yy +"/"+ mm+"/"+dd; 
           SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
           Date date=sdf.parse(birthday);
           vo.setBirthday(date);
           dao.insert(vo);
           System.out.println(vo.toString());
           return "redirect:/students/list";
       }
       
       
       
       
       
       @RequestMapping("read")
       public String read(String scode, Model model) throws Exception{
           model.addAttribute("vo"dao.read(scode));
           return "/students/read";
       }
       @RequestMapping(value="update", method=RequestMethod.POST)
       public String update(StudentsVO vo) throws Exception{
           dao.update(vo);
           System.out.println(vo.toString());
           return "redirect:/students/list";
       }
       @RequestMapping(value="delete", method=RequestMethod.POST)
       public String delete(String scode) throws Exception{
           dao.delete(scode);
           return "redirect:/students/list";
       }
}
 
 
 

<src>-<main>-<webapp>-<WEB-INF>-<views>-<students>-<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
60
<%@ 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="f" %>
<!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>학생목록</title>
   <style>
       a {text-decoration:none; color:skyblue;}
       .active{color:orange;}
   </style>
</head>
<body>
    <h1>[학생목록]</h1>
    <button onClick="location.href='insert'">학생등록</button>
      데이터:<b>${pm.totalCount}<b>
    <table border=1 width=800>
       <tr>
          <th width=50>학생번호</th>
          <th width=100>학생이름</th>
          <th width=100>학생학과</th>
          <th width=100>생년월일</th>
          <th widtn=200>담당교수</th>
          <th width=75>학년</th>
          <th width=50>수정</th>
          <th width=75>수강신청</th>
       </tr>
       <c:forEach items="${list}" var="vo">
        <tr>
            <td>${vo.scode}</td>
            <td>${vo.sname}</td>
            <td>${vo.dept}</td>
           <td><f:formatDate value="${vo.birthday}" pattern="yyyy-MM-dd"/></td>
            <td>${vo.pname}</td>
            <td>${vo.year}</td>
            <td><button onClick="location.href='read?scode=${vo.scode}'">수정</button></td>
            <td><button onClick="location.href='../enrollments/enroll?scode=${vo.scode}'">수강신청</button></td>
        </tr>
       </c:forEach> 
    </table>
    
    <div id="pagination">
          <c:if test="${pm.prev}">
            <a href="list?page=${pm.startPage-1}"></a>
          </c:if>
          <c:forEach begin="${pm.startPage}" end="${pm.endPage}" var="i">
          <c:if test="${i==pm.cri.page}">
             [<a class="active" href="list?page=${i}">${i}</a>]
          </c:if>
          <c:if test="${i!=pm.cri.page}">
             [<a href="list?page=${i}">${i}</a>]
          </c:if>
          </c:forEach>
          <c:if test="${pm.next}">
           <a href="list?page=${pm.endPage+1}"></a>
          </c:if>
    </div>
</body>
</html>
 
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

<src>-<main>-<webapp>-<WEB-INF>-<views>-<students>-<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 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>학생등록</title>
</head>
<body>
     <h1>[학생등록]</h1>
     <form action="insert" method="post">
        <table border=1 width=700>
           <tr>
             <td>학생번호</td>
             <td><input type="text" name="scode"></td>
            </tr>
            <tr> 
              <td>학생이름</td>
              <td><input type="text" name="sname"></td>
            </tr>
            <tr>
             <td>학생학과</td>
               <td>
                 <select name="dept">
                    <option>전산</option>
                    <option>건축</option>
                    <option>전자</option>
                 </select>
               </td>
             </tr>
             <tr>
             <td>학년</td>
               <td>
                 <input  name ="year" type="radio" value="1" checked>1
                 <input  name ="year" type="radio" value="2">2
                 <input  name ="year" type="radio" value="3">3
                 <input  name ="year" type="radio" value="4">
               </td>
             </tr>
             <tr>
                 <td>생년월일</td>
                 <td>
                     <input type="text" name="yy" size=4 value="2000">
                     <input type="text" name="mm" size=2>
                     <input type="text" name="dd" size=2>
                     (입력예시:2000년10월04일)
                 </td>
             </tr>
             <tr>
                 <td>담당교수</td>
                 <td><input type="text" name="advisor"></td>
             </tr>
        </table>
        <input type="submit" value="저장">
        <input type="reset" value="취소">
        <input type="button" value="목록" onClick="location.href='list'">
     </form>
</body>
</html>
 
 

<src>-<main>-<webapp>-<WEB-INF>-<views>-<students>-<read.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<%@ 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 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>학생현황</title>
</head>
<body>
     <h1>[학생현황]</h1>
     <form action="frm" method="post">
        <table border=1 width=700>
           <tr>
             <td>학생번호</td>
             <td><input type="text" name="scode" value="${vo.scode}"></td>
           </tr>
           <tr> 
              <td>학생이름</td>
              <td><input type="text" name="sname" value="${vo.sname}"></td>
           </tr>
           <tr>
             <td>학생학과</td>
               <td>
                 <select name="dept">
                    <option value="전산" <c:out value="${vo.dept=='전산'?'selected':'' }"/>>전산</option>
                    <option value="건축" <c:out value="${vo.dept=='건축'?'selected':'' }"/>>건축</option>
                    <option value="전자" <c:out value="${vo.dept=='전자'?'selected':'' }"/>>전자</option>
                 </select>
               </td>
            </tr>
            <tr>
             <td>학년</td>
               <td>
                 <input  name ="year" type="radio" value="1" <c:out value="${vo.year=='1'?'checked':''}"/>>1
                 <input  name ="year" type="radio" value="2" <c:out value="${vo.year=='2'?'checked':''}"/>>2
                 <input  name ="year" type="radio" value="3" <c:out value="${vo.year=='3'?'checked':''}"/>>3
                 <input  name ="year" type="radio" value="4" <c:out value="${vo.year=='4'?'checked':''}"/>>4 
               </td>
            </tr>
            <!-- 
            <tr>
                 <td>생년월일</td>
                 <td>
                     <input type="text" name="yy" size=4 value="${vo.birthday}">년
                     <input type="text" name="mm" size=2 value="${vo.birthday}">월
                     <input type="text" name="dd" size=2 value="${vo.birthday}">일
                     (입력예시:2000년10월04일)
                 </td>
             </tr>
              -->
        </table>
        <input type="button" value="수정" onClick="funUpdate()">
        <input type="reset" value="취소">
        <input type="button" value="목록" onClick="location.href='list'">
        <input type="button" value="삭제" onClick="funDelete()">
     </form>
</body>
    <script>
    function funUpdate(){
        var scode=$(frm.scode).val();
        var sname=$(frm.sname).val();
        var dept=$(frm.dept).val();
        var year=$(frm.year).val();
        alert(scode +"-"+ sname +"-"+ dept +"-"+ year);
        /*
        if(!confirm("수정하시겠습니까?")) return;
        frm.action="update";
        frm.submit();
        */
    }
    function funDelete(){
        if(!confirm("삭제하시겠습니까?")) return;
        frm.acttion="delete";
        frm.submit();
    }
    </script>
</html>
 
 

 

<수강신청 프로그램>

<com.example.domain>-<EnrollVO.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
 
 
import com.fasterxml.jackson.annotation.JsonFormat;
 
public class EnrollVO {
    private String lcode;
    private String lname;
    
    
    @JsonFormat(pattern="yyyy-MM-dd")
    private Date edate;
    
    private String scode;
    private int grade;
    private String sname;
    
    
    public String getLcode() {
        return lcode;
    }
    public void setLcode(String lcode) {
        this.lcode = lcode;
    }
    public String getLname() {
        return lname;
    }
    public void setLname(String lname) {
        this.lname = lname;
    }
    public Date getEdate() {
        return edate;
    }
    public void setEdate(Date edate) {
        this.edate = edate;
    }
    public String getScode() {
        return scode;
    }
    public void setScode(String scode) {
        this.scode = scode;
    }
    public int getGrade() {
        return grade;
    }
    public void setGrade(int grade) {
        this.grade = grade;
    }
    public String getSname() {
        return sname;
    }
    public void setSname(String sname) {
        this.sname = sname;
    }
    @Override
    public String toString() {
        return "EnrollVO [lcode=" + lcode + ", lname=" + lname + ", edate=" + edate + ", scode=" + scode + ", grade="
                + grade + ", sname=" + sname + "]";
    }
    
    
    
    
    
}
 
 
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

<com.example.persistence>-<EnrollDAO.Interface>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package com.example.persistence;
 
 
 
public interface EnrollDAO {
    public List<EnrollVO> slist(String scode) throws Exception;
    public void delete(String scode,String lcode) throws Exception;
    public void insert(EnrollVO vo) throws Exception;
    
    public List<EnrollVO> clist(String lcode) throws  Exception;
    public void update(EnrollVO vo) throws Exception;
}
 
 
 
 

<com.example.persistence>-<EnrollDAOImpl.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
package com.example.persistence;
 
 
 
import org.springframework.stereotype.Repository;
 
 
@Repository
public class EnrollDAOImpl implements EnrollDAO{
    @Inject
    SqlSession session;
    private static final String namespace="EnrollmentsMapper";
    @Override
    public List<EnrollVO> slist(String scode) throws Exception {
        // TODO Auto-generated method stub
        return session.selectList(namespace +".slist",scode);
    }
    @Override
    public void delete(String scode, String lcode) throws Exception {
        // TODO Auto-generated method stub
        HashMap<String, Object> map=new HashMap<String, Object>(); 
         
        map.put("scode", scode);
        map.put("lcode", lcode);
        
        session.delete(namespace+".delete",map);
    }
    @Override
    public void insert(EnrollVO vo) throws Exception {
        // TODO Auto-generated method stub
        session.insert(namespace+".insert",vo);
    }
    @Override
    public List<EnrollVO> clist(String lcode) throws Exception {
        // TODO Auto-generated method stub
        return session.selectList(namespace+".clist",lcode);
    }
    @Override
    public void update(EnrollVO vo) throws Exception {
        // TODO Auto-generated method stub
        session.update(namespace +".update",vo);
    }
 
}
 
 
 

<com.example.web>-<EnrollController.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
 
 
 
import org.springframework.stereotype.Controller;
 
import com.example.persistence.CoursesDAO;
import com.example.persistence.EnrollDAO;
import com.example.persistence.StudentsDAO;
 
@Controller
@RequestMapping("/enrollments/*")
public class EnrollController {
    @Inject
    StudentsDAO sdao;
    @Inject
    CoursesDAO cdao;
    
    @Inject
    EnrollDAO edao;
    
    @RequestMapping("enroll")
    public String enroll(String scode,Model model) throws Exception{
        model.addAttribute("svo",sdao.read(scode));
        model.addAttribute("clist",cdao.list());
        
        return "/enrollments/enroll";
    }
    @ResponseBody
    @RequestMapping("slist.json")
    public List<EnrollVO> slist(String scode) throws Exception{
        return edao.slist(scode);
    }
    
    @ResponseBody
    @RequestMapping(value="delete",method=RequestMethod.POST)
    public void delete(String scode,String lcode) throws Exception{
            edao.delete(scode, lcode);
    }
    
    @ResponseBody
    @RequestMapping(value="insert",method=RequestMethod.POST)
    public String insert(EnrollVO vo) {
        String result="";
        try{
            
            edao.insert(vo);
            
            result="SUCCESS";
            
        }catch(Exception e){
            
            result="FAIL";
        }
        
        return result;
    }
    
    
    @RequestMapping("grade")
    public String grade(CoursesVO vo,Model model){
        model.addAttribute("cvo",vo);
        return "/enrollments/grade";
    }
    
    @ResponseBody
    @RequestMapping("clist.json")
    public List<EnrollVO> clist(String lcode) throws Exception{
        return edao.clist(lcode);
    }
    
 
    @ResponseBody
    @RequestMapping("update")
    public void update(EnrollVO vo) throws Exception{
         edao.update(vo);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
 
 
 

<src/resource/java>-<mappers>-<EnrollmentsMapper.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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
<mapper namespace="EnrollmentsMapper">
    <select id="slist" resultType="com.example.domain.EnrollVO">
        select e.lcode,c.lname,e.edate 
        from  courses c,enrollments e
        where e.scode=#{scode} and  e.lcode=c.lcode
    </select>
    <delete id="delete">
        delete from enrollments 
        where scode=#{scode} and lcode=#{lcode}
    </delete>
    <insert id="insert">
        insert into 
        enrollments(lcode,edate,scode,grade) 
        values(#{lcode},now(),#{scode},0)
    </insert>
    <select id="clist" resultType="com.example.domain.EnrollVO">
        
        select e.scode,s.sname,e.grade from students s,enrollments e
        where e.lcode=#{lcode} and e.scode=s.scode
    </select>
    <update id="update">
        update enrollments 
        set grade=#{grade} 
        where lcode=#{lcode} and scode=#{scode}
    </update>
</mapper>
 
 

<src>-<main>-<webapp>-<WEB-INF>-<views>-<enrollments>-<enroll.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
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
<%@ 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 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>수강신청 목록</title>
    <style>
        .title{
            background:skyblue; color:gray;
        }
        .row{
            color:gray;
        }
        .middle{
            background:skyblue; 
            color:gray; 
            width:580px;
            margin-top:10px;
            padding:10px;
        }
        .in,.out{
            color:gray;
        }
    </style>
    <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
    
</head>
<body>
    <h1>[수강신청 목록]</h1>
    <table border=1 width=600>
    <tr >
        <th width=100 class="title">학번</th>
        <td width=100 class="title1">${svo.scode}</td>
        <th width=100 class="title">이름</th>
        <td width=100 class="title1">${svo.sname}</td>
        <th width=100 class="title">학과</th>
        <td width=100 class="title1">${svo.dept}</td>
    </tr>
    </table>
    
    <div class="middle">
        강좌명:
        <select id="lcode" class="out">
        <c:forEach items="${clist}" var="cvo">
                <option class="in" value="${cvo.lcode}">${cvo.lcode}:${cvo.lname}:${cvo.pname}:${cvo.room}</option>    
        </c:forEach>
        
        </select>
        <button id="funInsert">수강신청</button>
    </div>
    <h1>[학생이 수강신청한 목록]</h1>
    <table border=1 width=600 id="tbl"></table>
    <script id="temp" type="text/x-handlebars-template">
    <tr class="title">
        <td>강자코드</td>
        <td>강자이름</td>
        <td>수강신청일</td>
        <td>삭제</td>
    </tr>    
    {{#each .}}
    <tr class="row">
        <td>{{lcode}}</td>
        <td>{{lname}}</td>
        <td>{{edate}}</td>
        <td><button lcode="{{lcode}}">삭제</button></td>
    </tr>
    {{/each}}
    </script>
    <button onClick="location.href='../students/list'">목록이동</button>
</body>
<script>
    var scode="${svo.scode}"
 
    getList();
    $("#funInsert").on("click",function(){
        //alert("수강신청 입력");
        
        var lcode=$("#lcode option:selected").val();
        //alert(lcode+"-"+scode);
        
        $.ajax({
            type:"post",
            url:"insert",
            data:{"lcode":lcode,"scode":scode},
            success:function(result){
                if(result=="SUCCESS"){
                    getList();
                }else{
                    alert("이미 입력되었습니다.");
                }
            }
        });
        
    });
    
    $("#tbl").on("click",".row button"function(){
        if(!confirm("삭제하시겠습니까?"))return;
        var lcode=$(this).attr("lcode");
        //alert(scode +"-"+lcode);
        $.ajax({
            type:"post",
            url:"delete",
            data:{"scode":scode,"lcode":lcode},
            success:function(){
                alert("삭제되었습니다.");
                getList();
            }
        });
        
    });
    function getList(){
        $.ajax({
            type:"get",
            url:"slist.json",
            data:{"scode":scode},
            dataType:"json",
            success:function(data){
                var temp=Handlebars.compile($("#temp").html());
                $("#tbl").html(temp(data));
            }
        });
    }
</script>
</html>
 
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

<src>-<main>-<webapp>-<WEB-INF>-<views>-<enrollments>-<grade.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
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
<%@ 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 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>수강신청 목록</title>
    <style>
        .title{
            background:skyblue; color:gray;
        }
        .row{
            color:gray;
        }
        .middle{
            background:skyblue; 
            color:gray; 
            width:580px;
            margin-top:10px;
            padding:10px;
        }
        .in,.out{
            color:gray;
        }
    </style>
    <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
    
</head>
<body>
    <h1>[수강신청 목록]</h1>
    <table border=1 width=600>
    <tr >
        <th width=100 class="title">학번</th>
        <td width=100 class="title1">${svo.scode}</td>
        <th width=100 class="title">이름</th>
        <td width=100 class="title1">${svo.sname}</td>
        <th width=100 class="title">학과</th>
        <td width=100 class="title1">${svo.dept}</td>
    </tr>
    </table>
    
    <div class="middle">
        강좌명:
        <select id="lcode" class="out">
        <c:forEach items="${clist}" var="cvo">
                <option class="in" value="${cvo.lcode}">${cvo.lcode}:${cvo.lname}:${cvo.pname}:${cvo.room}</option>    
        </c:forEach>
        
        </select>
        <button id="funInsert">수강신청</button>
    </div>
    <h1>[학생이 수강신청한 목록]</h1>
    <table border=1 width=600 id="tbl"></table>
    <script id="temp" type="text/x-handlebars-template">
    <tr class="title">
        <td>강자코드</td>
        <td>강자이름</td>
        <td>수강신청일</td>
        <td>삭제</td>
    </tr>    
    {{#each .}}
    <tr class="row">
        <td>{{lcode}}</td>
        <td>{{lname}}</td>
        <td>{{edate}}</td>
        <td><button lcode="{{lcode}}">삭제</button></td>
    </tr>
    {{/each}}
    </script>
    <button onClick="location.href='../students/list'">목록이동</button>
</body>
<script>
    var scode="${svo.scode}"
 
    getList();
    $("#funInsert").on("click",function(){
        //alert("수강신청 입력");
        
        var lcode=$("#lcode option:selected").val();
        //alert(lcode+"-"+scode);
        
        $.ajax({
            type:"post",
            url:"insert",
            data:{"lcode":lcode,"scode":scode},
            success:function(result){
                if(result=="SUCCESS"){
                    getList();
                }else{
                    alert("이미 입력되었습니다.");
                }
            }
        });
        
    });
    
    $("#tbl").on("click",".row button"function(){
        if(!confirm("삭제하시겠습니까?"))return;
        var lcode=$(this).attr("lcode");
        //alert(scode +"-"+lcode);
        $.ajax({
            type:"post",
            url:"delete",
            data:{"scode":scode,"lcode":lcode},
            success:function(){
                alert("삭제되었습니다.");
                getList();
            }
        });
        
    });
    function getList(){
        $.ajax({
            type:"get",
            url:"slist.json",
            data:{"scode":scode},
            dataType:"json",
            success:function(data){
                var temp=Handlebars.compile($("#temp").html());
                $("#tbl").html(temp(data));
            }
        });
    }
</script>
</html>
 
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

<강좌 프로그램>

 

 

<com.example.domain>-<CoursesVO.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
 
public class CoursesVO {
    private String lcode;
    private String lname;
    private String pname;
    private String room;
    
    
    
    
    
    
    
    public String getLcode() {
        return lcode;
    }
    public void setLcode(String lcode) {
        this.lcode = lcode;
    }
    public String getLname() {
        return lname;
    }
    public void setLname(String lname) {
        this.lname = lname;
    }
    public String getPname() {
        return pname;
    }
    public void setPname(String pname) {
        this.pname = pname;
    }
    public String getRoom() {
        return room;
    }
    public void setRoom(String room) {
        this.room = room;
    }
    
    
    
    
    
    
    @Override
    public String toString() {
        return "CoursesVO [lcode=" + lcode + ", lname=" + lname + ", pname=" + pname + ", room=" + room + "]";
    }
    
    
    
    
}
 
 
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

 

<com.example.persistence>-<CoursesDAO.interface>

1
2
3
4
5
6
7
8
9
10
package com.example.persistence;
 
 
 
public interface CoursesDAO {
    public List<CoursesVO> list() throws Exception;
}
 
 
 

<com.example.persistence>-<CoursesDAOImpl.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
package com.example.persistence;
 
 
 
import org.springframework.stereotype.Repository;
 
 
@Repository
public class CoursesDAOImpl implements CoursesDAO{
    @Inject
    SqlSession session;
    private static final String  namespace="CoursesMapper";
    @Override
    public List<CoursesVO> list() throws Exception {
        // TODO Auto-generated method stub
        return session.selectList(namespace +".list");
    }
 
}
 
 
 

<com.example.web>-<CoursesController.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
 
 
 
 
import org.springframework.stereotype.Controller;
 
import com.example.persistence.CoursesDAO;
 
 
@Controller
@RequestMapping("/courses/*")
public class CoursesController {
    
    @Inject
    CoursesDAO dao;
    
    @RequestMapping("list")
    public String list(Model model) throws Exception{
        model.addAttribute("list",dao.list());
        return "/courses/list";
    }
    
}
 
 
 

<src/resource/java>-<mappers>-<CoursesMapper.xml>

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
<mapper namespace="CoursesMapper">
 
 
    <select id="list" resultType="com.example.domain.CoursesVO">
        select c.*,pname 
        from courses c,professors 
         where pcode=instructor
    </select>
</mapper>
 
 

<src>-<main>-<webapp>-<WEB-INF>-<views>-<courses>-<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
<%@ 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 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>강좌목록</title>
</head>
<body>
    <h1>[강좌목록]</h1>
    <table border=1 width=700>
    <tr>
        <th>강좌번호</th>
        <th>강좌이름</th>
        <th>담당교수</th>
        <th>강의실</th>
    </tr>    
    <c:forEach items="${list}" var="vo">
    <tr>
        <td>${vo.lcode}</td>
        <td>${vo.lname}</td>
        <td>${vo.pname}</td>
        <td>${vo.room}</td>
        <td><button onClick="location.href='../enrollments/grade?lcode=${vo.lcode}&lname=${vo.lname}'">성적입력</button></td>
    </tr>
    </c:forEach>
    </table>
</body>
</html>
 
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs