Browse Source

не работает скрипт последоватльного выбора в studentBar. Думаю...

Кинетик 6 years ago
parent
commit
c3d61fda20

+ 9 - 0
.idea/libraries/jstl_1_2.xml

@@ -0,0 +1,9 @@
+<component name="libraryTable">
+  <library name="jstl-1.2">
+    <CLASSES>
+      <root url="jar://$PROJECT_DIR$/web/WEB-INF/lib/jstl-1.2.jar!/" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+  </library>
+</component>

+ 10 - 0
.idea/webContexts.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="WebContextManager">
+    <option name="state">
+      <map>
+        <entry key="file://$PROJECT_DIR$/web/WEB-INF/views/studentBar.jsp" value="file://$PROJECT_DIR$/web/WEB-INF/views" />
+      </map>
+    </option>
+  </component>
+</project>

+ 1 - 0
MephorceAuth.iml

@@ -47,5 +47,6 @@
     <orderEntry type="library" name="Spring MVC-4.3.4.RELEASE" level="project" />
     <orderEntry type="library" name="Hibernate 5.2.3-5.2.3" level="project" />
     <orderEntry type="library" name="com.mysql.jdbc_5.1.5" level="project" />
+    <orderEntry type="library" name="jstl-1.2" level="project" />
   </component>
 </module>

+ 35 - 0
src/EntitiesDao/GroupDao.java

@@ -0,0 +1,35 @@
+package EntitiesDao;
+
+import HibernateEntities.GroupsEntity;
+import org.hibernate.Session;
+import org.hibernate.query.Query;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import static HibernateUtil.HibernateUtil.getSession;
+
+/**
+ * Created by Кинетик on 01.01.2017.
+ */
+public class GroupDao {
+    public static HashMap<String,Integer> getGroupMap() {
+        Session session = getSession();
+        Query query = session.createQuery("FROM GroupsEntity ");
+        List<GroupsEntity> res = query.list();
+        HashMap<String,Integer> groupMap = new HashMap<>();
+        for(GroupsEntity gr:res){
+            groupMap.put(gr.getGroupName(),gr.getGroupId());
+        }
+        session.close();
+        return groupMap;
+    }
+    public static List<GroupsEntity> getGroupList() {
+        Session session = getSession();
+        Query query = session.createQuery("FROM GroupsEntity ");
+        List<GroupsEntity> res = query.list();
+        session.close();
+        return res;
+    }
+}

+ 24 - 0
src/EntitiesDao/StudentDao.java

@@ -0,0 +1,24 @@
+package EntitiesDao;
+
+import HibernateEntities.StudentsEntity;
+import org.hibernate.Session;
+import org.hibernate.query.Query;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static HibernateUtil.HibernateUtil.getSession;
+
+/**
+ * Created by Кинетик on 01.01.2017.
+ */
+public class StudentDao {
+    public static List<StudentsEntity> loadStudent(Integer grId){
+        Session session = getSession();
+        Query query = session.createQuery("FROM StudentsEntity where stGroup="+grId);
+        List<StudentsEntity> res = query.list();
+        session.close();
+        return res;
+    }
+}

+ 1 - 1
src/HibernateEntities/GroupsEntity.java

@@ -6,7 +6,7 @@ import javax.persistence.*;
  * Created by Кинетик on 28.12.2016.
  */
 @Entity
-@Table(name = "groups", schema = "anketa", catalog = "")
+@Table(name = "groups", schema = "anketa")
 public class GroupsEntity {
     private int groupId;
     private String groupName;

+ 1 - 0
src/HibernateEntities/StudentsEntity.hbm.xml

@@ -6,6 +6,7 @@
 
     <class name="HibernateEntities.StudentsEntity" table="students" schema="anketa">
         <id name="studentsId" column="students_id"/>
+        <property name="stGroup" column="group_id"/>
         <property name="stFamily" column="st_family"/>
         <property name="stFirstName" column="st_first_name"/>
         <property name="stSecName" column="st_sec_name"/>

+ 12 - 1
src/HibernateEntities/StudentsEntity.java

@@ -6,13 +6,24 @@ import javax.persistence.*;
  * Created by Кинетик on 28.12.2016.
  */
 @Entity
-@Table(name = "students", schema = "anketa", catalog = "")
+@Table(name = "students", schema = "anketa")
 public class StudentsEntity {
     private int studentsId;
     private String stFamily;
     private String stFirstName;
     private String stSecName;
     private String stPkNumber;
+    private Integer stGroup;
+
+    @Basic
+    @Column(name = "group_id")
+    public Integer getStGroup() {
+        return stGroup;
+    }
+
+    public void setStGroup(Integer stGroup) {
+        this.stGroup = stGroup;
+    }
 
     @Id
     @Column(name = "students_id")

+ 15 - 5
src/controller/controller.java

@@ -2,22 +2,22 @@ package controller;
 
 
 import EntitiesDao.UsersDao;
-import HibernateEntities.ClientsEntity;
+import HibernateEntities.GroupsEntity;
+import HibernateEntities.StudentsEntity;
 import HibernateEntities.UsersEntity;
 import LoginEntities.LoginClient;
 import LoginEntities.LoginUser;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
-
 import java.util.*;
 
 import static EntitiesDao.AdminDao.getAdminList;
 import static EntitiesDao.AdminDao.getAdminMap;
 import static EntitiesDao.ClientsDao.getClientList;
 import static EntitiesDao.ClientsDao.getClientMap;
+import static EntitiesDao.GroupDao.getGroupList;
+import static EntitiesDao.StudentDao.loadStudent;
 
 /**
  * Created by Кинетик on 28.12.2016.
@@ -62,6 +62,9 @@ public class controller {
                     return mvClient;
                 } else {
                     mvUsers.addObject("message","");
+                    List<GroupsEntity> groupList = getGroupList();
+                    mvStudent.addObject("groupList",groupList);
+                    mvStudent.addObject("studentLogin", new LoginClient());
                     return mvStudent;
                 }
             } else {
@@ -112,4 +115,11 @@ public class controller {
         }
         return mv;
     }
+    @RequestMapping(value = "/loadStudents", headers = "Accept=*/*", method = RequestMethod.GET)
+    public @ResponseBody
+    List<StudentsEntity> loadStudents(@RequestParam(value = "groupId", required = true) Integer groupId) throws IllegalStateException {
+        List<StudentsEntity> stList = loadStudent(groupId);
+        return stList;
+    }
+
 }

BIN
web/WEB-INF/lib/jstl-1.2.jar


+ 36 - 3
web/WEB-INF/views/studentBar.jsp

@@ -1,3 +1,7 @@
+<%--suppress JSUnresolvedFunction --%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
+<%--suppress ALL --%>
 <%--
   Created by IntelliJ IDEA.
   User: Кинетик
@@ -5,12 +9,41 @@
   Time: 20:07
   To change this template use File | Settings | File Templates.
 --%>
-<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<!DOCTYPE html>
 <html>
 <head>
-    <title>Страница студента</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>JSP Page</title>
+    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
+    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
 </head>
+<c:url var="loadStudentsByGroup" value="/loadStudents" />
+<script type="text/javascript">
+    $(document).ready(function() {
+        $('#groupId').change(
+            function() {
+                $.getJSON('${loadStudentsByGroup}', {
+                    groupId : $(this).value(),
+                    ajax : 'true'
+                }, function(data) {
+                    var html = '<option value="">Первый элемент</option>';
+                    $('#studentId').html(html);
+                });
+            });
+    });
+</script>
+
 <body>
- <h1>Страница студента</h1>
+<form:form method="post" modelAttribute="studentLogin" action="checkStudent">
+    <form:select id="groupId" path="">
+        <c:forEach items="${groupList}" var="group">
+            <form:option value="${group.groupId}" >${group.groupName}</form:option>
+        </c:forEach><br/>
+    </form:select>
+    <form:select id="studentId" path="name">
+    </form:select>
+</form:form>
 </body>
 </html>
+