學生成績管理系統(SSM+MySQL+JSP)
開發工具:Eclipse
前端技術:
基礎:html+css+JavaScript
框架:JQuery+H-ui
後端技術:Spring+SpringMVC+mybatis
模板引擎:JSP
資料庫:mysql 5.7.27
jdk版本:1.8.0_251
tomcat版本:Tomcat 9.0
資料庫連接池:druid
一、功能概述
學生管理系統的用戶包括學生、教師及管理員。
(1)學生可以對個人的各科成績進行查詢、個人資訊修改、選課、修改登錄密碼等操作。
(2)教師可以對學生資訊、教師個人資訊、課程資訊、成績等進行管理,實現對這些資訊的查詢、錄入、添加、修改、刪除等操作。
(3)管理員可以對學生、教師、課程、成績資訊進行管理,實現對這些資訊的查詢、錄入、添加、修改、刪除以及許可權管理等操作。
功能結構圖:
二、資料庫表結構
成績表(Score):
學生表(student):
課程表(subject):
教師表(teacher):
用戶表(user):
三、項目結構
四、配置SSM文件
Spring-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="//www.springframework.org/schema/beans" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xmlns:context="//www.springframework.org/schema/context" xmlns:jdbc="//www.springframework.org/schema/jdbc" xmlns:jee="//www.springframework.org/schema/jee" xmlns:tx="//www.springframework.org/schema/tx" xmlns:util="//www.springframework.org/schema/util" xmlns:task="//www.springframework.org/schema/task" xsi:schemaLocation=" //www.springframework.org/schema/beans //www.springframework.org/schema/beans/spring-beans-4.0.xsd //www.springframework.org/schema/context //www.springframework.org/schema/context/spring-context-4.0.xsd //www.springframework.org/schema/jdbc //www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd //www.springframework.org/schema/jee //www.springframework.org/schema/jee/spring-jee-4.0.xsd //www.springframework.org/schema/tx //www.springframework.org/schema/tx/spring-tx-4.0.xsd //www.springframework.org/schema/util //www.springframework.org/schema/util/spring-util-4.0.xsd //www.springframework.org/schema/task //www.springframework.org/schema/task/spring-task-4.0.xsd" default-lazy-init="true"> <description>Spring Configuration</description> <!-- 載入配置屬性文件 --> <context:property-placeholder ignore-unresolvable="true" location="classpath:demo.properties" /> <!-- 使用Annotation自動註冊Bean,解決事物失效問題:在主容器中不掃描@Controller註解,在SpringMvc中只掃描@Controller註解。 --> <context:component-scan base-package="com.stusystem.controller"><!-- base-package 如果多個,用「,」分隔 --> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- MyBatis begin --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="typeAliasesPackage" value="com.stusystem.entity"/> <property name="mapperLocations" value="classpath:/com/stusystem/mappings/**/*.xml"/> <property name="configLocation" value="classpath:/mybatis-config.xml"></property> </bean> <!-- 掃描basePackage下所有以@MyBatisDao註解的介面 --> <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> <property name="basePackage" value="com.stusystem.dao"/> </bean> <!-- 定義事務,用@Transactiona註解表示事物 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 配置 Annotation 驅動,掃描@Transactional註解的類定義事務 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> <!-- MyBatis end --> <!-- 配置 JSR303 Bean Validator 定義 --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> <!-- 數據源配置, 使用 BoneCP 資料庫連接池 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 數據源驅動類可不寫,Druid默認會自動根據URL識別DriverClass --> <property name="driverClassName" value="${jdbc.driver}" /> <!-- 基本屬性 url、user、password --> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="${jdbc.pool.init}" /> <property name="minIdle" value="${jdbc.pool.minIdle}" /> <property name="maxActive" value="${jdbc.pool.maxActive}" /> <!-- 配置獲取連接等待超時的時間 --> <property name="maxWait" value="60000" /> <!-- 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一個連接在池中最小生存的時間,單位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="300000" /> <property name="validationQuery" value="${jdbc.testSql}" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <!-- 配置監控統計攔截的filters --> <property name="filters" value="stat" /> </bean> </beans>
Mybatis-config.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "//mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 全局參數 --> <settings> <!-- 使全局的映射器啟用或禁用快取。 --> <setting name="cacheEnabled" value="true"/> <!-- 全局啟用或禁用延遲載入。當禁用時,所有關聯對象都會即時載入。 --> <setting name="lazyLoadingEnabled" value="true"/> <!-- 當啟用時,有延遲載入屬性的對象在被調用時將會完全載入任意屬性。否則,每種屬性將會按需要載入。 --> <setting name="aggressiveLazyLoading" value="true"/> <!-- 是否允許單條sql 返回多個數據集 (取決於驅動的兼容性) default:true --> <setting name="multipleResultSetsEnabled" value="true"/> <!-- 是否可以使用列的別名 (取決於驅動的兼容性) default:true --> <setting name="useColumnLabel" value="true"/> <!-- 允許JDBC 生成主鍵。需要驅動器支援。如果設為了true,這個設置將強制使用被生成的主鍵,有一些驅動器不兼容不過仍然可以執行。 default:false --> <setting name="useGeneratedKeys" value="false"/> <!-- 指定 MyBatis 如何自動映射 數據基表的列 NONE:不隱射 PARTIAL:部分 FULL:全部 --> <setting name="autoMappingBehavior" value="PARTIAL"/> <!-- 這是默認的執行類型 (SIMPLE: 簡單; REUSE: 執行器可能重複使用prepared statements語句;BATCH: 執行器可以重複執行語句和批量更新) --> <setting name="defaultExecutorType" value="SIMPLE"/> <!-- 使用駝峰命名法轉換欄位。 --> <setting name="mapUnderscoreToCamelCase" value="true"/> <!-- 設置本地快取範圍 session:就會有數據的共享 statement:語句範圍 (這樣就不會有數據的共享 ) defalut:session --> <setting name="localCacheScope" value="SESSION"/> <!-- 設置但JDBC類型為空時,某些驅動程式 要指定值,default:OTHER,插入空值時不需要指定類型 --> <setting name="jdbcTypeForNull" value="NULL"/> </settings> </configuration>
spring-mvc.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="//www.springframework.org/schema/beans" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xmlns:context="//www.springframework.org/schema/context" xmlns:mvc="//www.springframework.org/schema/mvc" xsi:schemaLocation="//www.springframework.org/schema/beans //www.springframework.org/schema/beans/spring-beans-4.0.xsd //www.springframework.org/schema/context //www.springframework.org/schema/context/spring-context-4.0.xsd //www.springframework.org/schema/mvc //www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <description>Spring MVC Configuration</description> <!-- 載入配置屬性文件 --> <context:property-placeholder ignore-unresolvable="true" location="classpath:demo.properties" /> <!-- 使用Annotation自動註冊Bean,只掃描@Controller --> <context:component-scan base-package="com.stusystem" use-default-filters="false"><!-- base-package 如果多個,用「,」分隔 --> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 默認的註解映射的支援,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping --> <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"> <mvc:message-converters register-defaults="true"> <!-- 將StringHttpMessageConverter的默認編碼設為UTF-8 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8" /> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- REST中根據URL後綴自動判定Content-Type及相應的View --> <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <property name="mediaTypes" > <map> <entry key="xml" value="application/xml"/> <entry key="json" value="application/json"/> </map> </property> <property name="ignoreAcceptHeader" value="true"/> <property name="favorPathExtension" value="true"/> </bean> <!-- 定義視圖文件解析 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"/> <!-- <property name="suffix" value="${web.view.suffix}"/> --> <property name="suffix" value=".jsp"/> </bean> <!-- 對靜態資源文件的訪問, 將無法mapping到Controller的path交給default servlet handler處理 --> <mvc:default-servlet-handler /> <!-- 靜態資源映射 --> <mvc:resources mapping="/static/**" location="/static/" cache-period="31536000"/> <!-- 定義無Controller的path<->view直接映射 --> <mvc:view-controller path="/" view-name="redirect:${web.view.index}"/> <mvc:interceptors> <!--多個攔截器,順序執行 --> <!-- 登陸認證攔截器 --> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="com.stusystem.interceptor.LoginInterceptor"></bean> </mvc:interceptor> </mvc:interceptors> </beans>
五、配置web.xml和demo.properties
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xmlns="//java.sun.com/xml/ns/javaee" xsi:schemaLocation="//java.sun.com/xml/ns/javaee //java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>stusystem_3</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/spring-context*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <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> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>springServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/spring-mvc*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> <init-param> <param-name>allow</param-name> <param-value>127.0.0.1</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>600</session-timeout> </session-config> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/js/*</url-pattern> <url-pattern>/css/*</url-pattern> <url-pattern>/images/*</url-pattern> <url-pattern>/font/*</url-pattern> <url-pattern>/assets/*</url-pattern> <url-pattern>/lib/*</url-pattern> </servlet-mapping> </web-app>
demo.properties
#============================# #===== Database settings ====# #============================# #mysql database setting jdbc.type=mysql jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/stusystem?useUnicode=true&characterEncoding=utf-8 jdbc.username=root jdbc.password=123456 #pool settings jdbc.pool.init=1 jdbc.pool.minIdle=3 jdbc.pool.maxActive=20 #jdbc.testSql=SELECT 'x' jdbc.testSql=SELECT 'x' FROM DUAL web.view.prefix=/ web.view.suffix=.jsp web.view.index=/StuSystem/user/login
六、各個模組程式碼
UserBean.java: package com.stusystem.entity; import org.apache.ibatis.type.Alias; import org.springframework.stereotype.Component; @Alias("userbean") @Component public class Userbean { private String userName; private int userId; private String admin; private String password; private String xmm; public String getXmm() { return xmm; } public void setXmm(String xmm) { this.xmm = xmm; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public int getUserId() { return userId; } public void setUserId(int userId) { this.userId = userId; } public String getAdmin() { return admin; } public void setAdmin(String admin) { this.admin = admin; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
UserDao.java: package com.stusystem.dao; import com.stusystem.entity.Userbean; public interface UserDao { //驗證登錄資訊 public Userbean getUsrInfoByNameAndPsw(Userbean userbean); //修改密碼 public void mmxg(Userbean userbean); }
UserDao.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "//mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namesapce ,DAO的package路徑 --> <mapper namespace="com.stusystem.dao.UserDao"> <!-- 根據用戶輸入的用戶名和密碼查詢是否存在此用戶 --> <select id="getUsrInfoByNameAndPsw" parameterType="userbean" resultType="userbean"> select * from user where user_id=#{userId} and password=#{password} and admin=#{admin} </select> <!-- 修改登錄用戶的密碼 --> <update id="mmxg" parameterType="userbean"> UPDATE user SET password = #{xmm} WHERE (user_id=#{userId}) </update> </mapper>
UserController.java: package com.stusystem.controller; import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.stusystem.dao.UserDao; import com.stusystem.entity.Userbean; @Controller @RequestMapping(value = "user") public class UserController { @Autowired private UserDao userDao; // ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-context.xml"); // UserDao userDao = (UserDao) applicationContext.getBean("userDao"); //返回登陸介面 //驗證用戶的用戶名和密碼是有和資料庫中的匹配 @RequestMapping(value = {"/login"}) public String userlogin() { return "login"; } //登陸驗證 @RequestMapping(value = {"/loginyanzheng"}) public void loginyanzheng(Userbean userbean,HttpServletResponse response,HttpServletRequest request) throws IOException { Userbean user = userDao.getUsrInfoByNameAndPsw(userbean); if(user==null){ response.getWriter().println("{\"status\":0,\"msg\":\"用戶名或密碼有誤!\"}"); }else{ // 用戶的資訊存放到session中。 HttpSession session = request.getSession(); session.setAttribute("userbean", user); response.getWriter().println("{\"status\":1,\"url\":\"index\"}"); } } //返回系統主介面 @RequestMapping(value = {"/index"}) public String index() { return "index"; } //返回關於頁面 @RequestMapping(value = {"/gy"}) public String guanyu() { return "gy"; } //返回密碼修改頁面 @RequestMapping(value = {"/dlmmxg"}) public String dlmmxg() { return "dlmmxg"; } //修改登錄密碼 @RequestMapping(value = {"/mmxg"}) public String mmxg(Userbean userbean,HttpServletResponse response,HttpServletRequest request){ Userbean user = userDao.getUsrInfoByNameAndPsw(userbean); if(user==null){ request.setAttribute("status", '0'); }else{ userDao.mmxg(userbean); request.setAttribute("status", '1'); } return "dlmmxg"; } //退出系統 @RequestMapping(value = {"/loginout"}) public String loginout(HttpServletRequest request){ HttpSession session = request.getSession(); session.invalidate(); return "login"; } }
login.jsp <!DOCTYPE html> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html> <head> <meta http-equiv="content-type" content="text/html"> <meta charset="UTF-8"> <title>學生成績管理系統|登錄</title> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/host.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/animate.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font-awesome.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/js/validator-0.7.3/jquery.validator.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery-1.8.3.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/js/validator-0.7.3/jquery.validator.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/js/validator-0.7.3/local/zh_CN.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/js/host.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> function login() { var userid = document.getElementById("userid").value; var password = document.getElementById("password").value; var list = document.getElementsByName("inlineRadioOptions"); var admin = null; if(!list[0].checked&&!list[1].checked&&!list[2].checked){ return; } for(var i = 0 ; i < list.length ; i++){ if(list[i].checked){ admin = list[i].value; } } $.ajax({ type : "POST", data : "userId=" + userid + "&password=" + password +"&admin=" + admin, dataType : "json", url : "<%=request.getContextPath()%>/user/loginyanzheng", success : function(result) { if (result.status == 0) { swal("哦豁","用戶名或密碼有誤,請重新輸入!","error"); } else { swal({title:"太帥了",text:"登錄成功,進入系統!",type:"success"}, function () { location.href = "/StuSystem_3/user/index"; }); } } }); } </script> </head> <body bgcolor="#FFFFFF"> <div class="middle-box text-center loginscreen "> <div > <div class="animated animated lightSpeedIn "> <i class="icon iconfont">󰀨</i> </div> <h3>歡迎使用 學生成績管理系統</h3> <form class=" animated rollIn" data-validator-option="{theme:'yellow_right_effect',stopOnError:true}"> <div class="form-group"> <input type="text" class="form-control" placeholder="用戶名" data-rule="用戶名:required;digits" id = "userid"> </div> <div class="form-group"> <input type="password" class="form-control" placeholder="密碼" data-rule="密碼:required;password" id = "password"> </div> <fieldset> <label class="radio-inline" > <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="1" data-rule="checked"> 管理員 </label> <label class="radio-inline"> <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="2" > 教師 </label> <label class="radio-inline"> <input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="3" > 學生 </label> </fieldset> <br/> <br/> <button type="submit" class="btn btn-primary block full-width " onclick="login();">登 錄</button> </form> <br/> <br/> <div class = "animated bounceInLeft"> </div> </div> </div> <div class="part"></div> </body> </html>
index.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html> <head> <title>學生成績管理系統|首頁</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="<%=request.getContextPath()%>/assets/css/dpl-min.css" rel="stylesheet" type="text/css" /> <link href="<%=request.getContextPath()%>/assets/css/bui-min.css" rel="stylesheet" type="text/css" /> <link href="<%=request.getContextPath()%>/assets/css/main.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var index = layer.load(0, {shade: false}); //0代表載入的風格,支援0-2 </script> </head> <body> <div class="header"> <div class="dl-title"><span class="">學生成績管理系統</span></div> <div class="dl-log">歡迎您,<span class="dl-log-user">${userbean.userName}</span> <c:choose> <c:when test="${userbean.admin == 1}"> <span class="admin">(管理員)</span> </c:when> </c:choose> <c:choose> <c:when test="${userbean.admin == 2}"> <span class="admin">(教師)</span> </c:when> </c:choose> <c:choose> <c:when test="${userbean.admin == 3}"> <span class="admin">(學生)</span> </c:when> </c:choose> <a href="loginout" title="退出系統" class="dl-log-quit">[退出]</a> </div> </div> <div class="content"> <div class="dl-main-nav"> <ul id="J_Nav" class="nav-list ks-clear"> <li class="nav-item dl-selected"><div class="nav-item-inner nav-storage">首頁</div></li> </ul> </div> <ul id="J_NavContent" class="dl-tab-conten"> </ul> </div> <script type="text/javascript" src="<%=request.getContextPath()%>/assets/js/jquery-1.8.1.min.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/assets/js/bui-min.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/assets/js/config-min.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script> //學生登錄 if('${userbean.admin}'=='3'){ BUI.use('common/main',function(){ var config = [{ id:'menu', homePage:'gy', menu:[{ text:'學生操作', items:[ {id:'cjcx',text:'成績查詢',href:'/StuSystem_3/score/xsgrcjcx?studentId=' + '${userbean.userId}'}, {id:'xsgrkcgl',text:'學生個人課程管理',href:'/StuSystem_3/score/scoreone?page=1&studentId=' + '${userbean.userId}' }, {id:'xsgrxxgl',text:'學生個人資訊管理',href:'/StuSystem_3/student/studentone?stuId=' + '${userbean.userId}' }, {id:'dlmmxg',text:'登錄密碼修改',href:'/StuSystem_3/user/dlmmxg'}, {id:'gy',text:'關於',href:'gy'} ] }] }]; new PageUtil.MainPage({ modulesConfig : config }); }); } //教師登錄 if('${userbean.admin}'=='2'){ BUI.use('common/main',function(){ var config = [{ id:'menu', homePage:'gy', menu:[{ text:'教師操作', items:[ {id:'xsxxgl',text:'學生資訊管理',href:'/StuSystem_3/teacher/teacherlist?page=1'}, {id:'kcxxgl',text:'課程資訊管理',href:'/StuSystem_3/student/studentlist?page=1'}, {id:'jsgrxxgl',text:'教師個人資訊管理',href:'/StuSystem_3/teacher/teacherone?teacherId='+'${userbean.userId}'}, {id:'xscjgl',text:'學生成績管理',href:'/StuSystem_3/score/scorelist?page=1'}, {id:'dlmmxg',text:'登錄密碼修改',href:'/StuSystem_3/user/dlmmxg'}, {id:'gy',text:'關於',href:'gy'} ] }] }]; new PageUtil.MainPage({ modulesConfig : config }); }); } //管理員登錄 if('${userbean.admin}'=='1'){ BUI.use('common/main',function(){ var config = [{ id:'menu', homePage:'gy', menu:[{ text:'管理員操作', items:[ {id:'jsxxgl',text:'教師資訊管理',href:'/StuSystem_3/teacher/teacherlist?page=1'}, {id:'xsxxgl',text:'學生資訊管理',href:'/StuSystem_3/student/studentlist?page=1'}, {id:'kcxxgl',text:'課程資訊管理',href:'/StuSystem_3/subject/subjectlist?page=1'}, {id:'xscjgl',text:'學生成績管理',href:'/StuSystem_3/score/scorelist?page=1'}, {id:'dlmmxg',text:'登錄密碼修改',href:'/StuSystem_3/user/dlmmxg'}, {id:'gy',text:'關於',href:'gy'} ] }] }]; new PageUtil.MainPage({ modulesConfig : config }); }); } </script> </body> </html>
dlmmxg.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="<%=request.getContextPath()%>/css/H-ui.css" rel="stylesheet" type="text/css" /> <link href="<%=request.getContextPath()%>/css/H-ui.1.x.patch.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery-1.8.3.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/Validform.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/passwordStrength-min.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> $(function(){ $("#demoform-2").Validform({ tiptype:2, usePlugin:{ datepicker:{},//日期控制項校驗; passwordstrength:{ minLen:6,//設置密碼長度最小值,默認為0; maxLen:18,//設置密碼長度最大值,默認為30; trigger:function(obj,error){ //該表單元素的keyup和blur事件會觸發該函數的執行; //obj:當前表單元素jquery對象; //error:所設密碼是否符合驗證要求,驗證不能通過error為true,驗證通過則為false; //console.log(error); if(error){ obj.parent().find(".Validform_checktip").show(); obj.parent().find(".passwordStrength").hide(); }else{ obj.parent().find(".passwordStrength").show(); } } } } }); }); </script> <title>教師資訊編輯頁面</title> </head> <body> <form action="mmxg" method="post" class="form form-horizontal responsive" id="demoform-2"> <div class="row cl"> <label class="form-label col-2">舊密碼:</label> <div class="formControls col-5"> <input type="text" name="userId" id = "userId" value="${userbean.userId}" style="display:none;"/> <input type="text" name="admin" id = "admin" value="${userbean.admin}" style="display:none;"/> <input type="password" class="input-text" placeholder="請輸入舊密碼" name="password" id="password" datatype="*6-16" nullmsg="舊密碼不能為空" value = ""> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">新密碼:</label> <div class="formControls col-5"> <input type="password" class="input-text" autocomplete="off" placeholder="密碼" name="xmm" id="password1" datatype="*6-18" nullmsg="請輸入密碼!" > </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">密碼驗證:</label> <div class="formControls col-5"> <input type="password" class="input-text" autocomplete="off" placeholder="密碼" name="password2" id="password2" recheck="xmm" datatype="*6-18" nullmsg="請再輸入一次密碼!" errormsg="您兩次輸入的密碼不一致!" > </div> <div class="col-5"> </div> </div> <div class="row cl"> <div class="col-10 col-offset-2"> <input class="btn btn-primary" type="submit" onclick="tijiao();" value=" 提交 "> </div> </div> </form> </body> <script type="text/javascript"> if("${status}" == '1'){ swal({title:"密碼修改成功!",text:"您已經向伺服器了這條資訊!",type:"success"}, function () { location.href = "dlmmxg"; }); }else if("${status}" == '0'){ swal("哦豁","修改失敗失敗,請確保密碼輸入正確!","error"); }else{} </script> </html>
(2)學生模組
StudentBean.java: package com.stusystem.entity; public class StudentBean { private int stuId; private String stuName; private String stuSex; private String stuSystem; private String stuClass; private String stuPhone; private int page; public int getPage() { return (page-1)*6; } public void setPage(int page) { this.page = page; } public int getStuId() { return stuId; } public void setStuId(int stuId) { this.stuId = stuId; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public String getStuSex() { return stuSex; } public void setStuSex(String stuSex) { this.stuSex = stuSex; } public String getStuSystem() { return stuSystem; } public void setStuSystem(String stuSystem) { this.stuSystem = stuSystem; } public String getStuClass() { return stuClass; } public void setStuClass(String stuClass) { this.stuClass = stuClass; } public String getStuPhone() { return stuPhone; } public void setStuPhone(String stuPhone) { this.stuPhone = stuPhone; } }
StudentDao.java: package com.stusystem.dao; import java.util.List; import com.stusystem.entity.StudentBean; public interface StudentDao { public List<StudentBean> getStudent(StudentBean studentbean) throws Exception;//返回學生資訊的list public int getstupage(StudentBean studentbean) throws Exception;//分頁處理 public StudentBean getStudentone (StudentBean studentbean) throws Exception;//返回一條學生資訊 public void studentdel(StudentBean studentbean) throws Exception;//刪除一條學生資訊 public void studentadd(StudentBean studentbean) throws Exception;//增加一條學生資訊 public void studentxiugai(StudentBean studentbean) throws Exception;//修改一條學生資訊 }
StudentDao.xml: ```java <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "//mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namespace ,DAO的package路徑 --> <mapper namespace="com.stusystem.dao.StudentDao"> <!-- 查詢出多條學生資訊 --> <select id="getStudent" parameterType="com.stusystem.entity.StudentBean" resultType="com.stusystem.entity.StudentBean"> <if test=" stuName != null and stuName != '' "> SELECT * FROM student where stu_name = #{stuName} limit #{page} , 6 </if> <if test=" stuName == null or stuName == '' "> SELECT * FROM student limit #{page} , 6 </if> </select> <!--分頁處理 --> <select id="getstupage" parameterType="com.stusystem.entity.StudentBean" resultType="int"> <if test=" stuName != null and stuName != '' "> select count(*) from student where stu_name = #{stuName} </if> <if test=" stuName == null or stuName == '' "> select count(*) from student </if> </select> <!--根據id查詢出一條學生資訊--> <select id="getStudentone" parameterType="com.stusystem.entity.StudentBean" resultType="com.stusystem.entity.StudentBean" > SELECT * FROM student WHERE stu_id=#{stuId} </select> <!-- 刪除一條學生資訊 --> <delete id="studentdel" parameterType="com.stusystem.entity.StudentBean" > DELETE FROM student WHERE (stu_id=#{stuId}) </delete> <!-- 修改一條學生資訊 --> <update id="studentxiugai" parameterType="com.stusystem.entity.StudentBean"> UPDATE student SET stu_name=#{stuName}, stu_sex=#{stuSex}, stu_system=#{stuSystem}, stu_phone=#{stuPhone}, stu_class=#{stuClass} WHERE (stu_id=#{stuId}) </update> <!-- 添加一條學生資訊 --> <insert id="studentadd" parameterType="com.stusystem.entity.StudentBean"> INSERT INTO student (stu_name, stu_sex, stu_system, stu_phone, stu_class) VALUES (#{stuName},#{stuSex},#{stuSystem},#{stuPhone},#{stuClass}) </insert> </mapper>
StudentController.java package com.stusystem.controller; import java.io.IOException; import java.net.URLDecoder; import java.util.List; import javax.servlet.http.HttpServletResponse; 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 com.stusystem.dao.StudentDao; import com.stusystem.entity.StudentBean; @Controller @RequestMapping(value = "student") public class StudentController { @Autowired private StudentDao studentDao; // ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-context.xml"); // StudentDao studentDao = (StudentDao) applicationContext.getBean("studentDao"); //得到學生列表和頁數.返回到學生資訊頁面 @RequestMapping(value = {"/studentlist"}) public String getStudent(StudentBean stu,Model model) throws Exception{ if(stu.getStuName()!=null&&stu.getStuName()!=""){ stu.setStuName(URLDecoder.decode(stu.getStuName(), "UTF-8")); } List<StudentBean> stulist = studentDao.getStudent(stu); int stupage = studentDao.getstupage(stu); model.addAttribute("studentlist", stulist); model.addAttribute("stupage", stupage); model.addAttribute("studentname", stu.getStuName()); return "studentlist"; } //得到一個學生資訊。返回到一個學生資訊頁面 @RequestMapping(value = {"/studentone"}) public String getStudentone(StudentBean stu,Model model) throws Exception { StudentBean studentone = studentDao.getStudentone(stu); model.addAttribute("stuone", studentone); return "studentone"; } //得到一個學生資訊。返回到學生編輯頁面 @RequestMapping(value = {"/studenteditor"}) public String studenteditor(StudentBean stu,Model model) throws Exception { if(stu.getStuId()==0){ return "studenteditor"; }else{ StudentBean studentone = studentDao.getStudentone(stu); model.addAttribute("studentone", studentone); return "studenteditor"; } } //刪除學生資訊 @RequestMapping(value = {"/studentdel"}) public void studentdel(StudentBean stu,HttpServletResponse response) throws IOException { int a = 0; try { studentDao.studentdel(stu); } catch (Exception e) { a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); }else{ } } //添加/修改 ( 以是否有stuId來判斷) 學生資訊 @RequestMapping(value = {"/studentadd"}) public void studentadd(StudentBean stu,HttpServletResponse response) throws IOException{ int a = 0; try { if(stu.getStuId()==0){ stu.setStuName(URLDecoder.decode(stu.getStuName(), "UTF-8")); stu.setStuSystem(URLDecoder.decode(stu.getStuSystem(), "UTF-8")); stu.setStuSex(URLDecoder.decode(stu.getStuSex(), "UTF-8")); stu.setStuClass(URLDecoder.decode(stu.getStuClass(), "UTF-8")); studentDao.studentadd(stu); }else{ stu.setStuName(URLDecoder.decode(stu.getStuName(), "UTF-8")); stu.setStuSystem(URLDecoder.decode(stu.getStuSystem(), "UTF-8")); stu.setStuSex(URLDecoder.decode(stu.getStuSex(), "UTF-8")); stu.setStuClass(URLDecoder.decode(stu.getStuClass(), "UTF-8")); studentDao.studentxiugai(stu); } } catch (Exception e) { a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); }else{ } } }
studentlist.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> function del(studentid) { swal({ title: "您確定要刪除這條資訊嗎", text: "刪除後將無法恢復,請謹慎操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "刪除", closeOnConfirm: false }, function () { if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status== 1){ swal({title:"刪除成功!",text:"您已經永久刪除了這條資訊!",type:"success"}, function () { var b = '${stupage}' ; b = Math.ceil(b/6) ; location.href = "studentlist?page=" + b; }); }else{ swal("哦豁","刪除失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","studentdel?stuId="+studentid,true); xmlhttp.send(); }); } </script> <title>學生列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">學生資訊管理表</h2></div> <div class="col-md-4"></div> </div> </div> <div class="row"> <div class="col-md-3"> <div class="input-group"> <input type="text" class="form-control" placeholder="輸入學生姓名搜索" id = "sousuo" value = "${studentname}"> <span class="input-group-btn"> <button class="btn btn-default" type="button" onclick="sousuo();">Go!</button> </span> </div> </div> <div class="col-md-3"><button type="button" class="btn btn-default" onclick="tianjia();">添加+</button></div> <div class="col-md-6"></div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>學號</th> <th>學生姓名</th> <th>學生性別</th> <th>所在系</th> <th>班級</th> <th>電話號碼</th> <th>操作</th> </tr> <c:forEach items="${studentlist}" var="stu"> <tr> <td>${stu.stuId}</td> <td>${stu.stuName}</td> <td>${stu.stuSex}</td> <td>${stu.stuSystem}</td> <td>${stu.stuClass}</td> <td>${stu.stuPhone}</td> <td><button type="button" class="btn btn-info btn-xs" onclick="bianji(${stu.stuId});" ><i class="iconfont"></i> 編輯</button> <button type="button" onclick="del(${stu.stuId});" class="btn btn-danger btn-xs"><i class="iconfont"></i> 刪除</button></td> </tr> </c:forEach> </table> <div id="page11" style="margin-top:5px; text-align:center;"></div> </body> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script type="text/javascript"> laypage({ cont: 'page11', pages: Math.ceil("${stupage}"/6), //可以叫服務端把總頁數放在某一個隱藏域,再獲取。假設我們獲取到的是18 length skip: true, //是否開啟跳頁 skin: '#6699FF', curr: function(){ //通過url獲取當前頁,也可以同上(pages)方式獲取 var page = location.search.match(/page=(\d+)/); return page ? page[1] : 1; }(), jump: function(e, first){ //觸發分頁後的回調 if(!first){ //一定要加此判斷,否則初始時會無限刷新 var studengtname = document.getElementById("sousuo").value; location.href = '?page='+e.curr + '&stuName=' + encodeURI(encodeURI(studengtname)); } } }); </script> <script type="text/javascript"> function bianji(studentId) { layer.open({ type: 2, title: '學生資訊編輯頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'studenteditor?stuId='+ studentId }); } function tianjia() { layer.open({ type: 2, title: '學生資訊添加頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'studenteditor?stuId=0' }); } </script> <script type="text/javascript"> function sousuo() { var studentname = document.getElementById("sousuo").value; location.href = 'studentlist?stuName='+ encodeURI(encodeURI(studentname)) + '&page=1' ; } </script> </html>
studentone.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <title>學生資訊列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">學生個人資訊管理表</h2></div> <div class="col-md-4"></div> </div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>學號</th> <th>學生姓名</th> <th>學生性別</th> <th>所在系</th> <th>班級</th> <th>電話號碼</th> <th>操作</th> </tr> <tr> <td>${stuone.stuId}</td> <td>${stuone.stuName}</td> <td>${stuone.stuSex}</td> <td>${stuone.stuSystem}</td> <td>${stuone.stuClass}</td> <td>${stuone.stuPhone}</td> <td> <button id = "xiugai" type="button" class="btn btn-info btn-xs" οnclick="xiugai();" > <i class="iconfont"></i> 編輯 </button> </td> </tr> </table> </body> <script type="text/javascript"> function xiugai() { layer.open({ type: 2, title: '學生個人資訊修改頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'studenteditor?stuId='+"${stuone.stuId}" }); } </script> </html>
studenteditor.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="<%=request.getContextPath()%>/css/H-ui.css" rel="stylesheet" type="text/css" /> <link href="<%=request.getContextPath()%>/css/H-ui.1.x.patch.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery-1.8.3.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/Validform.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/passwordStrength-min.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> $(function(){ $("#demoform-2").Validform({ tiptype:2, usePlugin:{ datepicker:{},//日期控制項校驗; passwordstrength:{ minLen:6,//設置密碼長度最小值,默認為0; maxLen:18,//設置密碼長度最大值,默認為30; trigger:function(obj,error){ //該表單元素的keyup和blur事件會觸發該函數的執行; //obj:當前表單元素jquery對象; //error:所設密碼是否符合驗證要求,驗證不能通過error為true,驗證通過則為false; //console.log(error); if(error){ obj.parent().find(".Validform_checktip").show(); obj.parent().find(".passwordStrength").hide(); }else{ obj.parent().find(".passwordStrength").show(); } } } } }); }); </script> <title>教師資訊編輯頁面</title> </head> <body> <form action="" method="post" class="form form-horizontal responsive" id="demoform-2"> <div class="row cl"> <label class="form-label col-2">姓名:</label> <div class="formControls col-5"> <input type="text" name="studentid" id = "studentid" value="${studentone.stuId}" style="display:none;"/> <input type="text" class="input-text" placeholder="請輸入學生姓名" name="studentname" id="studentname" datatype="s2-5" nullmsg="學生姓名不能為空" value = "${studentone.stuName}"> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">所在系:</label> <div class="formControls col-5"> <input type="text" class="input-text" placeholder="請輸入學生所在系" name="studentsystem" id="studentsystem" datatype="s2-10" nullmsg="所在系不能為空" value = "${studentone.stuSystem}"> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">電話號碼:</label> <div class="formControls col-5"> <input type="text" class="input-text" autocomplete="off" placeholder="手機號碼" name="studentphone" id="studentphone" datatype="m" nullmsg="電話號碼不能為空" value = "${studentone.stuPhone}"> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">班級:</label> <div class="formControls col-5"> <input type="text" class="input-text" placeholder="請輸入學生班級" name="studentclass" id="studentclass" datatype="s2-10" nullmsg="班級不能為空" value = "${studentone.stuClass}"> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">學生性別:</label> <div class="formControls skin-minimal col-5"> <div class="radio-box"> <input type="radio" id="sex-1" name="studentsex" value = "男" datatype="*" nullmsg="請選擇性別!"> <label for="sex-1">男</label> </div> <div class="radio-box"> <input type="radio" id="sex-2" name="studentsex" value = "女"> <label for="sex-2">女</label> </div> </div> <div class="col-5"> </div> </div> <div class="row cl"> <div class="col-10 col-offset-2"> <input class="btn btn-primary" type="button" οnclick="hehe();" id = "tijiao" value=" 提交 "> </div> </div> </form> </body> <script type="text/javascript"> if('${studentone.stuSex}' =="女"){ document.getElementById('sex-2').checked="checked"; }else if('${studentone.stuSex}' =="男") { document.getElementById('sex-1').checked="checked"; }else{ } </script> <script type="text/javascript"> function hehe() { var studentname = document.getElementById("studentname").value; var studentsystem = document.getElementById("studentsystem").value; var studentid = document.getElementById("studentid").value; if(studentid==""){ studentid = 0; } var studentphone = document.getElementById("studentphone").value; var studentclass = document.getElementById("studentclass").value; var list = document.getElementsByName("studentsex"); var studentsex = null; for(var i = 0 ; i < list.length ; i++){ if(list[i].checked){ studentsex = list[i].value; } } if(studentname==""||studentsystem==""||studentphone==""||studentclass==""||studentsex==""){ swal("哦豁","提交失敗,請重試!","error"); return; } if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status == 1){ swal({title:"提交成功!",text:"您已經向伺服器了這條資訊!",type:"success"}, function () { parent.top.topManager.reloadPage(); parent.layer.closeAll(); }); }else{ swal("哦豁","提交失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","studentadd?stuName="+encodeURI(encodeURI(studentname)) + "&stuSystem=" + encodeURI(encodeURI(studentsystem))+ "&stuId=" + studentid + "&stuPhone=" + encodeURI(encodeURI(studentphone))+ "&stuClass=" + encodeURI(encodeURI(studentclass))+ "&stuSex=" + encodeURI(encodeURI(studentsex)) ,true); xmlhttp.send(); } </script> </html>
(3)教師模組
TeacherBean.java package com.stusystem.entity; import org.apache.ibatis.type.Alias; import org.springframework.stereotype.Component; @Alias("teacherBean") @Component public class TeacherBean { private int teacherId; private String teacherName; private String teacherSex; private String teacherSystem; private String teacherPhone; private String teacherEmail; public String getTeacherEmail() { return teacherEmail; } public void setTeacherEmail(String teacherEmail) { this.teacherEmail = teacherEmail; } private int page; public int getPage() { return (page-1)*6; } public void setPage(int page) { this.page = page; } public int getTeacherId() { return teacherId; } public void setTeacherId(int teacherId) { this.teacherId = teacherId; } public String getTeacherName() { return teacherName; } public void setTeacherName(String teacherName) { this.teacherName = teacherName; } public String getTeacherSystem() { return teacherSystem; } public String getTeacherSex() { return teacherSex; } public void setTeacherSex(String teacherSex) { this.teacherSex = teacherSex; } public void setTeacherSystem(String teacherSystem) { this.teacherSystem = teacherSystem; } public String getTeacherPhone() { return teacherPhone; } public void setTeacherPhone(String teacherPhone) { this.teacherPhone = teacherPhone; } }
TeacherDao.java package com.stusystem.dao; import com.stusystem.entity.*; import java.util.*; public interface TeacherDao { public List<TeacherBean> getTeacher(TeacherBean teacherbean) throws Exception; public int getteapage(TeacherBean teacherbean) throws Exception;//返回教師資訊有多少頁 public TeacherBean getTeacherone(TeacherBean teacherbean) throws Exception;//根據Id返回一條教師記錄 public void teacherdel(TeacherBean teacherbean) throws Exception; public void teacheradd(TeacherBean teacherbean) throws Exception; public void teacherxiugai(TeacherBean teacherbean) throws Exception; }
TeacherDao.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "//mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namespace ,DAO的package路徑 --> <mapper namespace="com.stusystem.dao.TeacherDao"> <select id="getTeacher" parameterType="teacherBean" resultType="teacherBean"> <if test=" teacherName != null and teacherName != '' "> SELECT * FROM teacher where teacher_name = #{teacherName} limit #{page} , 6 </if> <if test=" teacherName == null or teacherName == '' "> SELECT * FROM teacher limit #{page} , 6 </if> </select> <!-- 查詢出所有教師資訊可以分為多少頁,在前端做分頁處理 --> <select id="getteapage" parameterType="teacherBean" resultType="int"> <if test=" teacherName != null and teacherName != '' "> select count(*) from `teacher` where teacher_name = #{teacherName} </if> <if test=" teacherName == null or teacherName == '' "> select count(*) from `teacher` </if> </select> <!-- 根據id查詢出一條教師資訊 --> <select id="getTeacherone" parameterType="teacherBean" resultType="teacherBean" > SELECT * FROM teacher WHERE teacher_id=#{teacherId} </select> <!-- 刪除一條教師記錄 --> <delete id="teacherdel" parameterType="teacherBean" > DELETE FROM `teacher` WHERE (`teacher_id`=#{teacherId}) </delete> <!--修改一條教師記錄 --> <update id="teacherxiugai" parameterType="teacherBean"> UPDATE teacher SET teacher_name=#{teacherName}, teacher_sex=#{teacherSex}, teacher_system=#{teacherSystem}, teacher_phone=#{teacherPhone}, teacher_email=#{teacherEmail} WHERE (teacher_id=#{teacherId}) </update> <!-- 添加一條教師記錄 --> <insert id="teacheradd" parameterType="teacherBean"> INSERT INTO `teacher` (`teacher_name`, `teacher_sex`, `teacher_system`, `teacher_phone`, `teacher_email`) VALUES (#{teacherName},#{teacherSex},#{teacherSystem},#{teacherPhone},#{teacherEmail}) </insert> </mapper>
TeacherController,java package com.stusystem.controller; import java.io.IOException; import java.net.URLDecoder; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; 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 com.stusystem.dao.TeacherDao; import com.stusystem.entity.TeacherBean; @Controller @RequestMapping("teacher") public class TeacherController { @Autowired TeacherDao teacherDao; @RequestMapping("/teacherlist") public String getTeacher(TeacherBean tea,Model model,HttpServletRequest request) throws Exception{ if(tea.getTeacherName()!=null&&tea.getTeacherName()!=""){ tea.setTeacherName(URLDecoder.decode(tea.getTeacherName(), "UTF-8")); } List<TeacherBean> teacherlist=teacherDao.getTeacher(tea); int teapage=teacherDao.getteapage(tea); model.addAttribute("teacherlist",teacherlist); model.addAttribute("teapage",teapage); model.addAttribute("teachername",tea.getTeacherName()); return "teacherlist"; } @RequestMapping("/teacherone") public String getTeacherone(TeacherBean tea,Model model) throws Exception{ TeacherBean teacherone=teacherDao.getTeacherone(tea); model.addAttribute("teaone",teacherone); return "teacherone"; } @RequestMapping("/teachereditor") public String teachereditor(TeacherBean tea,Model model) throws Exception{ if(tea.getTeacherId()==0) { return "teachereditor"; }else { TeacherBean teacherone=teacherDao.getTeacherone(tea); model.addAttribute("teacherone",teacherone); return "teachereditor"; } } @RequestMapping("/teacherdel") public void teacherdel(TeacherBean tea,HttpServletResponse response) throws IOException{ int a = 0; try { teacherDao.teacherdel(tea); } catch (Exception e) { a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); }else{ } } //添加一條教師用戶資訊 @RequestMapping(value = {"/teacheradd"}) public void teacheradd(TeacherBean tea,HttpServletResponse response) throws IOException{ int a = 0; try { if(tea.getTeacherId()==0){ tea.setTeacherName(URLDecoder.decode(tea.getTeacherName(), "UTF-8")); tea.setTeacherSystem(URLDecoder.decode(tea.getTeacherSystem(), "UTF-8")); tea.setTeacherSex(URLDecoder.decode(tea.getTeacherSex(), "UTF-8")); tea.setTeacherEmail(URLDecoder.decode(tea.getTeacherEmail(), "UTF-8")); teacherDao.teacheradd(tea); }else{ tea.setTeacherName(URLDecoder.decode(tea.getTeacherName(), "UTF-8")); tea.setTeacherSystem(URLDecoder.decode(tea.getTeacherSystem(), "UTF-8")); tea.setTeacherSex(URLDecoder.decode(tea.getTeacherSex(), "UTF-8")); tea.setTeacherEmail(URLDecoder.decode(tea.getTeacherEmail(), "UTF-8")); teacherDao.teacherxiugai(tea); } } catch (Exception e) { a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); }else{ } } }
teacherlist.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> function del(teacherid) { swal({ title: "您確定要刪除這條資訊嗎", text: "刪除後將無法恢復,請謹慎操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "刪除", closeOnConfirm: false }, function () { if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status== 1){ swal({title:"刪除成功!",text:"您已經永久刪除了這條資訊!",type:"success"}, function () { var b = '${teapage}' ; b = Math.ceil(b/6) ; location.href = "teacherlist?page="+b; }); }else{ swal("哦豁","刪除失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","teacherdel?teacherId="+teacherid,true); xmlhttp.send(); }); } </script> <title>教師列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">教師資訊管理表</h2></div> <div class="col-md-4"></div> </div> </div> <div class="row"> <div class="col-md-3"> <div class="input-group"> <input type="text" class="form-control" id ="sousuo" placeholder="輸入教師姓名搜索" value = "${teachername}" > <span class="input-group-btn"> <button class="btn btn-default" type="button" onclick="sousuo();">Go!</button> </span> </div> </div> <div class="col-md-3"><button type="button" class="btn btn-default" onclick="tianjia();">添加+</button></div> <div class="col-md-6"></div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>教師編號</th> <th>教師姓名</th> <th>教師性別</th> <th>所在系</th> <th>電話號碼</th> <th>郵箱</th> <th>操作</th> </tr> <c:forEach items="${teacherlist}" var="tea"> <tr> <td>${tea.teacherId}</td> <td>${tea.teacherName}</td> <td>${tea.teacherSex}</td> <td>${tea.teacherSystem}</td> <td>${tea.teacherPhone}</td> <td>${tea.teacherEmail}</td> <td><button type="button" class="btn btn-info btn-xs" onclick="bianji(${tea.teacherId});" ><i class="iconfont"></i> 編輯</button> <button type="button" onclick="del(${tea.teacherId});" class="btn btn-danger btn-xs"><i class="iconfont"></i> 刪除</button></td> </tr> </c:forEach> </table> <div id="page11" style="margin-top:5px; text-align:center;"></div> </body> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script type="text/javascript"> laypage({ cont: 'page11', pages: Math.ceil("${teapage}"/6), //可以叫服務端把總頁數放在某一個隱藏域,再獲取。假設我們獲取到的是18 skip: true, //是否開啟跳頁 skin: '#6699FF', curr: function(){ //通過url獲取當前頁,也可以同上(pages)方式獲取 var page = location.search.match(/page=(\d+)/); return page ? page[1] : 1; }(), jump: function(e, first){ //觸發分頁後的回調 if(!first){ //一定要加此判斷,否則初始時會無限刷新 var teachername = document.getElementById("sousuo").value; location.href = '?page='+e.curr + '&teacherName=' + encodeURI(encodeURI(teachername)); } } }); </script> <script type="text/javascript"> function bianji(teacherId) { layer.open({ type: 2, title: '教師資訊編輯頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'teachereditor?teacherId='+ teacherId }); } function tianjia() { layer.open({ type: 2, title: '教師資訊編輯頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'teachereditor?teacherId=0' }); } </script> <script type="text/javascript"> function sousuo() { var teachername = document.getElementById("sousuo").value; location.href = 'teacherlist?teacherName='+ encodeURI(encodeURI(teachername)) + '&page=1' ; } </script> </html>
teacherone.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <title>教師資訊列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">教師個人資訊管理表</h2></div> <div class="col-md-4"></div> </div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>教師編號</th> <th>教師姓名</th> <th>教師性別</th> <th>系別</th> <th>電話號碼</th> <th>郵箱</th> <th>操作</th> </tr> <tr> <td>${teaone.teacherId}</td> <td>${teaone.teacherName}</td> <td>${teaone.teacherSex}</td> <td>${teaone.teacherSystem}</td> <td>${teaone.teacherPhone}</td> <td>${teaone.teacherEmail}</td> <td> <button id = "xiugai" type="button" class="btn btn-info btn-xs" οnclick="xiugai();" > <i class="iconfont"></i> 編輯 </button> </td> </tr> </table> </body> <script type="text/javascript"> function xiugai() { layer.open({ type: 2, title: '學生個人資訊修改頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'teachereditor?teacherId='+"${teaone.teacherId}" }); } </script> </html>
teachereditor.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="<%=request.getContextPath()%>/css/H-ui.css" rel="stylesheet" type="text/css" /> <link href="<%=request.getContextPath()%>/css/H-ui.1.x.patch.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery-1.8.3.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/Validform.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/passwordStrength-min.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> $(function(){ $("#demoform-2").Validform({ tiptype:2, usePlugin:{ datepicker:{},//日期控制項校驗; passwordstrength:{ minLen:6,//設置密碼長度最小值,默認為0; maxLen:18,//設置密碼長度最大值,默認為30; trigger:function(obj,error){ //該表單元素的keyup和blur事件會觸發該函數的執行; //obj:當前表單元素jquery對象; //error:所設密碼是否符合驗證要求,驗證不能通過error為true,驗證通過則為false; //console.log(error); if(error){ obj.parent().find(".Validform_checktip").show(); obj.parent().find(".passwordStrength").hide(); }else{ obj.parent().find(".passwordStrength").show(); } } } } }); }); </script> <title>教師資訊編輯頁面</title> </head> <body> <form action="" class="form form-horizontal responsive" id="demoform-2"> <div class="row cl"> <label class="form-label col-2">姓名:</label> <div class="formControls col-5"> <input type="text" name="teacherid" id = "teacherid" value="${teacherone.teacherId}" style="display:none;"/> <input type="text" value = "${teacherone.teacherName}" class="input-text" placeholder="請輸入教師姓名" name="teachername" id="teachername" datatype="s2-5" nullmsg="教師姓名不能為空" > </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">所在系:</label> <div class="formControls col-5"> <input type="text" class="input-text" placeholder="請輸入教師所在系" name="teachersystem" id="teachersystem" datatype="s2-10" nullmsg="請輸入所在系" value = '${teacherone.teacherSystem}' > </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">電話號碼:</label> <div class="formControls col-5"> <input type="text" class="input-text" autocomplete="off" placeholder="手機號碼" name="teacherphone" id="teacherphone" datatype="m" nullmsg="電話號碼不能為空" value = '${teacherone.teacherPhone}'> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">郵箱:</label> <div class="formControls col-5"> <input type="text" class="input-text" placeholder="@" name="teacheremail" id="teacheremail" datatype="e" nullmsg="請輸入郵箱!" value = '${teacherone.teacherEmail}'> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">教師性別:</label> <div class="formControls skin-minimal col-5"> <div class="radio-box"> <input type="radio" id="sex-1" value = "男" name="teachersex" datatype="*" nullmsg="請選擇性別!" > <label for="sex-1">男</label> </div> <div class="radio-box"> <input type="radio" id="sex-2" name="teachersex" value = "女"> <label for="sex-2">女</label> </div> </div> <div class="col-5"> </div> </div> <div class="row cl"> <div class="col-10 col-offset-2"> <input class="btn btn-primary" type="button" οnclick="hehe();" id = "tijiao" value=" 提交 "> </div> </div> </form> </body> <script type="text/javascript"> if('${teacherone.teacherSex}' =="女"){ document.getElementById('sex-2').checked="checked"; }else if('${teacherone.teacherSex}' =="男") { document.getElementById('sex-1').checked="checked"; }else{ } </script> <script type="text/javascript"> function hehe() { var teachername = document.getElementById("teachername").value; var teachersystem = document.getElementById("teachersystem").value; var teacherid = document.getElementById("teacherid").value; if(teacherid==""){ teacherid = 0; } var teacherphone = document.getElementById("teacherphone").value; var teacheremail = document.getElementById("teacheremail").value; var list = document.getElementsByName("teachersex"); var teachersex = null; for(var i = 0 ; i < list.length ; i++){ if(list[i].checked){ teachersex = list[i].value; } } if(teachername==""||teachersystem==""||teacherphone==""||teacheremail==""||teachersex==""){ swal("哦豁","提交失敗,請重試!","error"); return; } if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status == 1){ swal({title:"提交成功!",text:"您已經向伺服器了這條資訊!",type:"success"}, function () { parent.top.topManager.reloadPage();//刷新父頁 parent.layer.closeAll(); }); }else{ swal("哦豁","提交失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","teacheradd?teacherName="+encodeURI(encodeURI(teachername)) + "&teacherSystem=" + encodeURI(encodeURI(teachersystem))+ "&teacherId=" + encodeURI(encodeURI(teacherid))+ "&teacherPhone=" + encodeURI(encodeURI(teacherphone))+ "&teacherEmail=" + encodeURI(encodeURI(teacheremail))+ "&teacherSex=" + encodeURI(encodeURI(teachersex)) ,true); xmlhttp.send(); } </script> </html>
(4)課程模組
SubjectBean.java package com.stusystem.entity; public class SubjectBean { private int subjectId; private String subjectName; private String teacherName; private String subjectCredit; private int page; public int getPage() { return (page-1)*6; } public void setPage(int page) { this.page = page; } public int getSubjectId() { return subjectId; } public void setSubjectId(int subjectId) { this.subjectId = subjectId; } public String getSubjectName() { return subjectName; } public void setSubjectName(String subjectName) { this.subjectName = subjectName; } public String getTeacherName() { return teacherName; } public void setTeacherName(String teacherName) { this.teacherName = teacherName; } public String getSubjectCredit() { return subjectCredit; } public void setSubjectCredit(String subjectCredit) { this.subjectCredit = subjectCredit; } }
SubjectDao.java package com.stusystem.dao; import java.util.List; import com.stusystem.entity.SubjectBean; public interface SubjectDao { public List<SubjectBean> getSubject(SubjectBean subjectBean) throws Exception; public int getsbjpage(SubjectBean subjectBean) throws Exception; public SubjectBean getSubjectone(SubjectBean subjectBean) throws Exception; public void subjectdel(SubjectBean subjectBean) throws Exception; public void subjectadd(SubjectBean subjectBean) throws Exception; public void subjectxiugai(SubjectBean subjectBean) throws Exception; }
SubjectDao.xml `<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "//mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namesapce ,DAO的package路徑 --> <mapper namespace="com.stusystem.dao.SubjectDao"> <!-- 查詢所有課程資訊的list --> <select id="getSubject" parameterType="com.stusystem.entity.SubjectBean" resultType="com.stusystem.entity.SubjectBean"> <if test=" subjectName != null and subjectName != '' "> SELECT * FROM subject where subject_name = #{subjectName} limit #{page} , 6 </if> <if test=" subjectName == null or subjectName == '' "> SELECT * FROM subject limit #{page} , 6 </if> </select> <!-- 查詢課程資訊共有多少頁,分頁處理 --> <select id="getsbjpage" parameterType="com.stusystem.entity.SubjectBean" resultType="int"> <if test=" subjectName != null and subjectName != '' "> select count(*) from `subject` where subject_name = #{subjectName} </if> <if test=" subjectName == null or subjectName == '' "> select count(*) from `subject` </if> </select> <!-- 查詢一條課程資訊 --> <select id="getSubjectone" parameterType="com.stusystem.entity.SubjectBean" resultType="com.stusystem.entity.SubjectBean" > SELECT * FROM subject WHERE subject_id=#{subjectId} </select> <!-- 刪除一條課程資訊 --> <delete id="subjectdel" parameterType="com.stusystem.entity.SubjectBean" > DELETE FROM `subject` WHERE (`subject_id`=#{subjectId}) </delete> <!-- 修改一條課程資訊 --> <update id="subjectxiugai" parameterType="com.stusystem.entity.SubjectBean"> UPDATE subject SET subject_name=#{subjectName}, teacher_name=#{teacherName}, subject_credit=#{subjectCredit} WHERE (subject_id=#{subjectId}) </update> <!-- 添加一條課程資訊 --> <insert id="subjectadd" parameterType="com.stusystem.entity.SubjectBean"> INSERT INTO `subject` (`subject_name`, `teacher_name`, `subject_credit`) VALUES (#{subjectName},#{teacherName},#{subjectCredit}) </insert> </mapper>
ScoreController.java package com.stusystem.controller; import java.io.IOException; import java.net.URLDecoder; import java.util.List; import javax.servlet.http.HttpServletResponse; 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 com.stusystem.dao.SubjectDao; import com.stusystem.entity.SubjectBean; @Controller @RequestMapping("subject") public class SubjectController { @Autowired SubjectDao subjectDao; @RequestMapping("/subjectlist") public String getSubject(SubjectBean sbj,Model model) throws Exception{ if(sbj.getSubjectName()!=null&&sbj.getSubjectName()!=""){ sbj.setSubjectName(URLDecoder.decode(sbj.getSubjectName(), "UTF-8")); } List<SubjectBean> subjectlist=subjectDao.getSubject(sbj); int sbjpage=subjectDao.getsbjpage(sbj); model.addAttribute("subjectlist",subjectlist); model.addAttribute("sbjpage",sbjpage); model.addAttribute("subjectName", sbj.getSubjectName()); return "subjectlist"; } @RequestMapping("/subjecteditor") public String studenteditor(SubjectBean sbj,Model model) throws Exception { if(sbj.getSubjectId()==0){ return "subjecteditor"; }else{ SubjectBean subjectone = subjectDao.getSubjectone(sbj); model.addAttribute("subjectone", subjectone);//如subjecteditor.jsp中可用subjectone.sybjectId來獲取課程號 return "subjecteditor"; } } //刪除一條課程資訊 @RequestMapping(value = {"/subjectdel"}) public void subjectdel(SubjectBean sbj,HttpServletResponse response) throws IOException { int a = 0; try { subjectDao.subjectdel(sbj); } catch (Exception e) { a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); }else{ } } //添加一條課程資訊 @RequestMapping(value = {"/subjectadd"}) public void subjectadd(SubjectBean sbj,HttpServletResponse response) throws IOException{ int a = 0; try { if(sbj.getSubjectId()==0){ sbj.setSubjectName(URLDecoder.decode(sbj.getSubjectName(), "UTF-8")); sbj.setTeacherName(URLDecoder.decode(sbj.getTeacherName(), "UTF-8")); subjectDao.subjectadd(sbj); }else{ sbj.setSubjectName(URLDecoder.decode(sbj.getSubjectName(), "UTF-8")); sbj.setTeacherName(URLDecoder.decode(sbj.getTeacherName(), "UTF-8")); subjectDao.subjectxiugai(sbj); } } catch (Exception e) { a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); }else{ } } }
subjectlist.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> function del(studentid) { swal({ title: "您確定要刪除這條資訊嗎", text: "刪除後將無法恢復,請謹慎操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "刪除", closeOnConfirm: false }, function () { if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status== 1){ swal({title:"刪除成功!",text:"您已經永久刪除了這條資訊!",type:"success"}, function () { var b = '${stupage}' ; b = Math.ceil(b/6) ; location.href = "studentlist?page=" + b; }); }else{ swal("哦豁","刪除失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","studentdel?stuId="+studentid,true); xmlhttp.send(); }); } </script> <title>學生列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">學生資訊管理表</h2></div> <div class="col-md-4"></div> </div> </div> <div class="row"> <div class="col-md-3"> <div class="input-group"> <input type="text" class="form-control" placeholder="輸入學生姓名搜索" id = "sousuo" value = "${studentname}"> <span class="input-group-btn"> <button class="btn btn-default" type="button" onclick="sousuo();">Go!</button> </span> </div> </div> <div class="col-md-3"><button type="button" class="btn btn-default" onclick="tianjia();">添加+</button></div> <div class="col-md-6"></div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>學號</th> <th>學生姓名</th> <th>學生性別</th> <th>所在系</th> <th>班級</th> <th>電話號碼</th> <th>操作</th> </tr> <c:forEach items="${studentlist}" var="stu"> <tr> <td>${stu.stuId}</td> <td>${stu.stuName}</td> <td>${stu.stuSex}</td> <td>${stu.stuSystem}</td> <td>${stu.stuClass}</td> <td>${stu.stuPhone}</td> <td><button type="button" class="btn btn-info btn-xs" onclick="bianji(${stu.stuId});" ><i class="iconfont"></i> 編輯</button> <button type="button" onclick="del(${stu.stuId});" class="btn btn-danger btn-xs"><i class="iconfont"></i> 刪除</button></td> </tr> </c:forEach> </table> <div id="page11" style="margin-top:5px; text-align:center;"></div> </body> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script type="text/javascript"> laypage({ cont: 'page11', pages: Math.ceil("${stupage}"/6), //可以叫服務端把總頁數放在某一個隱藏域,再獲取。假設我們獲取到的是18 length skip: true, //是否開啟跳頁 skin: '#6699FF', curr: function(){ //通過url獲取當前頁,也可以同上(pages)方式獲取 var page = location.search.match(/page=(\d+)/); return page ? page[1] : 1; }(), jump: function(e, first){ //觸發分頁後的回調 if(!first){ //一定要加此判斷,否則初始時會無限刷新 var studengtname = document.getElementById("sousuo").value; location.href = '?page='+e.curr + '&stuName=' + encodeURI(encodeURI(studengtname)); } } }); </script> <script type="text/javascript"> function bianji(studentId) { layer.open({ type: 2, title: '學生資訊編輯頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'studenteditor?stuId='+ studentId }); } function tianjia() { layer.open({ type: 2, title: '學生資訊添加頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'studenteditor?stuId=0' }); } </script> <script type="text/javascript"> function sousuo() { var studentname = document.getElementById("sousuo").value; location.href = 'studentlist?stuName='+ encodeURI(encodeURI(studentname)) + '&page=1' ; } </script> </html>
subjectone.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <title>學生資訊列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">學生個人資訊管理表</h2></div> <div class="col-md-4"></div> </div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>學號</th> <th>學生姓名</th> <th>學生性別</th> <th>所在系</th> <th>班級</th> <th>電話號碼</th> <th>操作</th> </tr> <tr> <td>${stuone.stuId}</td> <td>${stuone.stuName}</td> <td>${stuone.stuSex}</td> <td>${stuone.stuSystem}</td> <td>${stuone.stuClass}</td> <td>${stuone.stuPhone}</td> <td> <button id = "xiugai" type="button" class="btn btn-info btn-xs" οnclick="xiugai();" > <i class="iconfont"></i> 編輯 </button> </td> </tr> </table> </body> <script type="text/javascript"> function xiugai() { layer.open({ type: 2, title: '學生個人資訊修改頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'studenteditor?stuId='+"${stuone.stuId}" }); } </script> </html>
subjecteditoe.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="<%=request.getContextPath()%>/css/H-ui.css" rel="stylesheet" type="text/css" /> <link href="<%=request.getContextPath()%>/css/H-ui.1.x.patch.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery-1.8.3.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/Validform.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/passwordStrength-min.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> $(function(){ $("#demoform-2").Validform({ tiptype:2, usePlugin:{ datepicker:{},//日期控制項校驗; passwordstrength:{ minLen:6,//設置密碼長度最小值,默認為0; maxLen:18,//設置密碼長度最大值,默認為30; trigger:function(obj,error){ //該表單元素的keyup和blur事件會觸發該函數的執行; //obj:當前表單元素jquery對象; //error:所設密碼是否符合驗證要求,驗證不能通過error為true,驗證通過則為false; //console.log(error); if(error){ obj.parent().find(".Validform_checktip").show(); obj.parent().find(".passwordStrength").hide(); }else{ obj.parent().find(".passwordStrength").show(); } } } } }); }); </script> <title>教師資訊編輯頁面</title> </head> <body> <form action="" class="form form-horizontal responsive" id="demoform-2"> <div class="row cl"> <label class="form-label col-2">課程名字:</label> <div class="formControls col-5"> <input type="text" name="subjectid" id = "subjectid" value="${subjectone.subjectId}" style="display:none;"/> <input type="text" class="input-text" placeholder="請輸入課程名字" name="subjectname" id="subjectname" value="${subjectone.subjectName}" datatype="s2-10" nullmsg="課程名字不能為空"> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">授課老師:</label> <div class="formControls col-5"> <input type="text" class="input-text" placeholder="請輸入授課老師" name="teachername" id="teachername" value="${subjectone.teacherName}" datatype="s2-5" nullmsg="授課老師不能為空"> </div> <div class="col-5"> </div> </div> <div class="row cl"> <label class="form-label col-2">學分:</label> <div class="formControls col-5"> <input type="text" class="input-text" autocomplete="off" placeholder="請輸入學分" name="subjectcredit" id="subjectcredit" value="${subjectone.subjectCredit}" datatype="n" nullmsg="學分不能為空"> </div> <div class="col-5"> </div> </div> <div class="row cl"> <div class="col-10 col-offset-2"> <input class="btn btn-primary" type="button" onclick="hehe();" value=" 提交 "> </div> </div> </form> </body> <script type="text/javascript"> function hehe() { var subjectid = document.getElementById("subjectid").value; if(subjectid==""){ subjectid = 0; } var subjectname = document.getElementById("subjectname").value; var teachername = document.getElementById("teachername").value; var subjectcredit = document.getElementById("subjectcredit").value; if(subjectname==""||teachername==""||subjectcredit==""){ swal("哦豁","提交失敗,請重試!","error"); return; } if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status == 1){ swal({title:"提交成功!",text:"您已經向伺服器了這條資訊!",type:"success"}, function () { parent.top.topManager.reloadPage(); parent.layer.closeAll(); }); }else{ swal("哦豁","提交失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","subjectadd?subjectId="+encodeURI(encodeURI(subjectid)) + "&subjectName=" + encodeURI(encodeURI(subjectname))+ "&teacherName=" + encodeURI(encodeURI(teachername))+ "&subjectCredit=" + encodeURI(encodeURI(subjectcredit)),true); xmlhttp.send(); } </script> </html>
(5)分數和選課模組
ScoreBean.java package com.stusystem.entity; import org.apache.ibatis.type.Alias; import org.springframework.stereotype.Component; @Alias("scoreBean") @Component public class ScoreBean { private int scoreId; private int studentId; private String subjectName; private String studentName; private String score; private int subjectId; private String teacherName; private String subjectCredit; private int page; public int getPage() { return (page-1)*6; } public void setPage(int page) { this.page = page; } public String getSubjectCredit() { return subjectCredit; } public void setSubjectCredit(String subjectCredit) { this.subjectCredit = subjectCredit; } public String getTeacherName() { return teacherName; } public void setTeacherName(String teacherName) { this.teacherName = teacherName; } public int getScoreId() { return scoreId; } public void setScoreId(int scoreId) { this.scoreId = scoreId; } public int getStudentId() { return studentId; } public void setStudentId(int studentId) { this.studentId = studentId; } public String getSubjectName() { return subjectName; } public void setSubjectName(String subjectName) { this.subjectName = subjectName; } public String getStudentName() { return studentName; } public void setStudentName(String studentName) { this.studentName = studentName; } public String getScore() { return score; } public void setScore(String score) { this.score = score; } public int getSubjectId() { return subjectId; } public void setSubjectId(int subjectId) { this.subjectId = subjectId; } }
ScoreDao.java package com.stusystem.dao; import java.util.List; import com.stusystem.entity.ScoreBean; import com.stusystem.entity.StudentBean; import com.stusystem.entity.SubjectBean; public interface ScoreDao { public List<ScoreBean> getscorelist(StudentBean studentBean) throws Exception; public void scoreadd(ScoreBean score) throws Exception; public List<SubjectBean> getSubject(ScoreBean score) throws Exception; //已選課程資訊的分頁處理 public int getsbjpage(ScoreBean score)throws Exception; //添加一個學生的選課資訊 public void setsubject(ScoreBean score)throws Exception; //查詢一個學生已選課程資訊的list public List<SubjectBean> yxsubjectlist(ScoreBean score) throws Exception; //刪除一條已選課程 public void delyxkc(ScoreBean score) throws Exception; //查詢一個學生的已選課程成績和課程資訊的list public List<ScoreBean> getscoreonelist(ScoreBean score)throws Exception; }
ScoreDao.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "//mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namesapce ,DAO的package路徑 --> <mapper namespace="com.stusystem.dao.ScoreDao"> <!-- 多表查詢查詢出一個學生的成績和其他資訊保存到一個score對象中 --> <select id="getscorelist" parameterType="com.stusystem.entity.StudentBean" resultType="scoreBean"> SELECT score.score, `subject`.subject_name, score.score_id FROM score , `subject` WHERE score.subject_id = `subject`.subject_id AND score.student_id = #{stuId} </select> <!-- 添加一個學生的成績 --> <update id="scoreadd" parameterType="scoreBean"> UPDATE score SET score=#{score} WHERE score_id=#{scoreId} </update> <!--查詢一個學生的未選選課程資訊list --> <select id="getSubject" parameterType="scoreBean" resultType="com.stusystem.entity.SubjectBean"> <if test=" subjectName != null and subjectName != '' ">select * from `subject` where subject_name = #{subjectName} and subject_id not in (select subject_id from score where student_id = #{studentId} ) limit #{page} ,6 </if> <if test=" subjectName == null or subjectName == '' "> SELECT * FROM subject where subject_id not in (select subject_id from score where student_id = #{studentId} ) limit #{page} ,6 </if> </select> <!-- 已選課程資訊的分頁處理 --> <select id="getsbjpage" parameterType="scoreBean" resultType="int"> <if test=" subjectName != null and subjectName != '' ">select count(*) from `subject` where subject_name = #{subjectName} and subject_id not in (select subject_id from score where student_id = #{studentId} )</if> <if test=" subjectName == null or subjectName == '' "> select count(*) from subject where subject_id not in (select subject_id from score where student_id = #{studentId} ) </if> </select> <!--添加一個學生的選課資訊 --> <insert id="setsubject" parameterType="scoreBean"> INSERT INTO `score` (`student_id`, `subject_id`) VALUES (#{studentId},#{subjectId}) </insert> <!-- 查詢一個學生已選課程資訊的list--> <select id="yxsubjectlist" parameterType="scoreBean" resultType="com.stusystem.entity.SubjectBean"> SELECT * FROM subject where subject_id in (select subject_id from score where student_id = #{studentId} ) </select> <!-- 刪除一條已選課程 --> <delete id="delyxkc" parameterType="scoreBean"> DELETE FROM `score` WHERE `student_id`=#{studentId} and subject_id = #{subjectId} </delete> <!-- 查詢一個學生的已選課程成績和課程資訊的list--> <select id="getscoreonelist" parameterType="scoreBean" resultType="scoreBean"> SELECT * FROM score , `subject` WHERE score.subject_id = `subject`.subject_id AND score.student_id = #{studentId} </select> </mapper>
ScoreController.java package com.stusystem.controller; import java.io.IOException; import java.net.URLDecoder; import java.util.List; import javax.servlet.http.HttpServletResponse; 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 com.stusystem.dao.ScoreDao; import com.stusystem.dao.StudentDao; import com.stusystem.entity.ScoreBean; import com.stusystem.entity.StudentBean; import com.stusystem.entity.SubjectBean; @Controller @RequestMapping(value = "score") public class ScoreController { @Autowired private StudentDao studentDao; //要注入必須要將這個類在spring容器中註冊 @Autowired private ScoreDao scoreDao; // ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-context.xml"); // StudentDao studentDao = (StudentDao) applicationContext.getBean("studentDao"); // ScoreDao scoreDao = (ScoreDao) applicationContext.getBean("scoreDao"); //查詢出所有學生資訊到學生成績管理頁面 @RequestMapping(value = {"/scorelist"}) public String getStudent(StudentBean stu,Model model) throws Exception{ if(stu.getStuName()!=null&&stu.getStuName()!=""){ stu.setStuName(URLDecoder.decode(stu.getStuName(), "UTF-8")); } List<StudentBean> stulist = studentDao.getStudent(stu); int stupage = studentDao.getstupage(stu); model.addAttribute("studentlist", stulist); model.addAttribute("stupage", stupage); model.addAttribute("studentname", stu.getStuName()); return "scorelist"; } //查詢出一個學生已選課程資訊list到該學生成績編輯頁面 @RequestMapping(value = {"/scoreeditor"}) public String scoreeditor(StudentBean stu,Model model) throws Exception{ List<ScoreBean> scorelist = scoreDao.getscorelist(stu); model.addAttribute("scorelist", scorelist); if(scorelist.size()==0){ model.addAttribute("h1", " 這位同學還沒有選課!!!"); } return "scoreeditor"; } //得到在編輯頁面編輯好一個學生的各科成績的list,循環存入資料庫中後,在返回存入結果 @RequestMapping(value = {"/scoreadd"}) public void scoreadd(String scorelist,HttpServletResponse response) throws IOException { int a = 0; String[] scoreStrArray = scorelist.split(","); ScoreBean score = new ScoreBean(); try{ for(int i = 0 ; i < scoreStrArray.length ; i+=2 ){ score.setScore(scoreStrArray[i]); score.setScoreId(Integer.parseInt(scoreStrArray[i+1])); scoreDao.scoreadd(score); } }catch (Exception e){ a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); } } //查詢出一個學生的未選課程的資訊list @RequestMapping(value = {"/scoreone"}) public String scoreone(ScoreBean scorebean,Model model)throws Exception{ String subjectname =scorebean.getSubjectName(); if (subjectname != null && !"".equals(subjectname)) { subjectname= URLDecoder.decode(subjectname, "UTF-8"); scorebean.setSubjectName(URLDecoder.decode(subjectname, "UTF-8")) ; } List<SubjectBean> subjectlist = scoreDao.getSubject(scorebean); int sbjpage = scoreDao.getsbjpage(scorebean); model.addAttribute("sbjpage", sbjpage); model.addAttribute("subjectlist", subjectlist); model.addAttribute("subjectname", subjectname); return "scoreone"; } //添加一個學生的選課記錄 @RequestMapping(value = {"/xuanke"}) public void xuanke(HttpServletResponse response,ScoreBean scorebean) throws IOException{ int a = 0; try { scoreDao.setsubject(scorebean); } catch (Exception e) { a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); } } //返回一個學生的已選課程的list到已選課程編輯頁面 @RequestMapping(value = {"/xsyxkc"}) public String xsyxkc(ScoreBean scorebean,Model model) throws Exception{ List<SubjectBean> yxsubjectlist = scoreDao.yxsubjectlist(scorebean); model.addAttribute("yxsubjectlist", yxsubjectlist); return "xsyxkc"; } //刪除一個學生的已選課程 @RequestMapping(value = {"/yxkcdel"}) public void yxkcdel(ScoreBean scorebean,HttpServletResponse response) throws IOException{ int a = 0; try { scoreDao.delyxkc(scorebean); } catch (Exception e) { a=a+1; response.getWriter().println("{'status':'0'}"); e.printStackTrace(); } if(a==0){ response.getWriter().println("{'status':'1'}"); } } //查詢出一個學生的已選課程成績資訊和相應成績 @RequestMapping(value = {"/xsgrcjcx"}) public String xsgrcjcx(ScoreBean scorebean,Model model)throws Exception{ List<ScoreBean> scoreonelist = scoreDao.getscoreonelist(scorebean); model.addAttribute("scoreonelist", scoreonelist); if(scoreonelist.size()==0){ model.addAttribute("h1", "你還沒有選課!!"); } return "xsgrcjcx"; } }
scorelist.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <title>學生列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">學生成績管理表</h2></div> <div class="col-md-4"></div> </div> </div> <div class="row"> <div class="col-md-3"> <div class="input-group"> <input type="text" class="form-control" placeholder="輸入學生姓名搜索" id = "sousuo" value = "${studentname}"> <span class="input-group-btn"> <button class="btn btn-default" type="button" onclick="sousuo();">Go!</button> </span> </div> </div> <div class="col-md-3"></div> <div class="col-md-6"></div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>學號</th> <th>學生姓名</th> <th>學生性別</th> <th>所在系</th> <th>班級</th> <th>電話號碼</th> <th>操作</th> </tr> <c:forEach items="${studentlist}" var="stu"> <tr> <td>${stu.stuId}</td> <td>${stu.stuName}</td> <td>${stu.stuSex}</td> <td>${stu.stuSystem}</td> <td>${stu.stuClass}</td> <td>${stu.stuPhone}</td> <td><button type="button" onclick="bianji(${stu.stuId});" class="btn btn-info btn-xs"><i class="iconfont"></i> 編輯該學生成績</button></td> </tr> </c:forEach> </table> <div id="page11" style="margin-top:5px; text-align:center;"></div> </body> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script type="text/javascript"> laypage({ cont: 'page11', pages: Math.ceil("${stupage}"/6), //可以叫服務端把總頁數放在某一個隱藏域,再獲取。假設我們獲取到的是18 length skip: true, //是否開啟跳頁 skin: '#6699FF', curr: function(){ //通過url獲取當前頁,也可以同上(pages)方式獲取 var page = location.search.match(/page=(\d+)/); return page ? page[1] : 1; }(), jump: function(e, first){ //觸發分頁後的回調 if(!first){ //一定要加此判斷,否則初始時會無限刷新 var studengtname = document.getElementById("sousuo").value; location.href = '?page='+e.curr + '&stuName=' + encodeURI(encodeURI(studengtname)); } } }); </script> <script type="text/javascript"> function bianji(studentid) { layer.open({ type: 2, title: '學生成績編輯頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'scoreeditor?stuId='+studentid }); } </script> <script type="text/javascript"> function sousuo() { var studentname = document.getElementById("sousuo").value; location.href = 'scorelist?stuName='+ encodeURI(encodeURI(studentname)) + '&page=1'; } </script> </html>
scoreone.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> function xuanze(subjectid,studentid) { swal({ title: "您確定要選擇本課程嗎?", text: "請選擇與本人專業相關的課程!!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "選擇", closeOnConfirm: false }, function () { if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status== 1){ swal({title:"選擇成功!",text:"您已經成功選擇了本課程!",type:"success"}, function () { location.href = "scoreone?page=1"+"&studentId="+'${userbean.userId}'; }); }else{ swal("哦豁","選擇失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","xuanke?subjectId="+ subjectid + "&studentId=" + studentid ,true); xmlhttp.send(); }); } </script> <title>課程列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">學生個人課程資訊管理表</h2></div> <div class="col-md-4"></div> </div> </div> <div class="row"> <div class="col-md-3"> <div class="input-group"> <input type="text" class="form-control" placeholder="輸入課程名搜索" id = "sousuo" value = "${subjectname}"> <span class="input-group-btn"> <button class="btn btn-default" type="button" onclick="sousuo();">Go!</button> </span> </div> </div> <div class="col-md-3"><button type="button" class="btn btn-default" onclick="yxkc();">查看已選擇課程</button></div> <div class="col-md-6"></div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>課程編號</th> <th>課程名字</th> <th>授課老師</th> <th>課程學分</th> <th>操作</th> </tr> <c:forEach items="${subjectlist}" var="sbj"> <tr> <td>${sbj.subjectId}</td> <td>${sbj.subjectName}</td> <td>${sbj.teacherName}</td> <td>${sbj.subjectCredit}</td> <td> <button id = "${sbj.subjectId}" type="button" class="btn btn-info btn-xs" οnclick="xuanze(${sbj.subjectId},${userbean.userId});" > <i class="iconfont"></i> 添加本課程 </button> </td> </tr> </c:forEach> </table> <div id="page11" style="margin-top:5px; text-align:center;"></div> </body> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script type="text/javascript"> var aa = Math.ceil("${sbjpage}"/6); laypage({ cont: 'page11', pages: aa, //可以叫服務端把總頁數放在某一個隱藏域,再獲取。假設我們獲取到的是18 length skip: true, //是否開啟跳頁 skin: '#6699FF', curr: function(){ //通過url獲取當前頁,也可以同上(pages)方式獲取 var page = location.search.match(/page=(\d+)/); return page ? page[1] : 1; }(), jump: function(e, first){ //觸發分頁後的回調 if(!first){ //一定要加此判斷,否則初始時會無限刷新 var subjectname = document.getElementById("sousuo").value; location.href = '?page='+e.curr + '&subjectName=' + encodeURI(encodeURI(subjectname)+'&studentId=' + '${userbean.userId}'); } } }); </script> <script type="text/javascript"> function sousuo() { var subjectname = document.getElementById("sousuo").value; location.href = 'scoreone?subjectName='+ encodeURI(encodeURI(subjectname)) + '&page=1' + '&studentId=' + '${userbean.userId}' ; } function yxkc() { layer.open({ type: 2, title: '學生已選課程資訊頁面', shadeClose: true, shade: 0.8, shift: 1, //0-6的動畫形式,-1不開啟 area: ['800px', '80%'], content: 'xsyxkc?studentId='+"${userbean.userId}" }); } </script> </html>
scoreeditor,jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="<%=request.getContextPath()%>/css/H-ui.css" rel="stylesheet" type="text/css" /> <link href="<%=request.getContextPath()%>/css/H-ui.1.x.patch.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery-1.8.3.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/Validform.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/lib/Validform/5.3.2/passwordStrength-min.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <script type="text/javascript"> $(function(){ $("#demoform-2").Validform({ tiptype:2, usePlugin:{ datepicker:{},//日期控制項校驗; passwordstrength:{ minLen:6,//設置密碼長度最小值,默認為0; maxLen:18,//設置密碼長度最大值,默認為30; trigger:function(obj,error){ //該表單元素的keyup和blur事件會觸發該函數的執行; //obj:當前表單元素jquery對象; //error:所設密碼是否符合驗證要求,驗證不能通過error為true,驗證通過則為false; //console.log(error); if(error){ obj.parent().find(".Validform_checktip").show(); obj.parent().find(".passwordStrength").hide(); }else{ obj.parent().find(".passwordStrength").show(); } } } } }); }); </script> <title>學生成績編輯頁面</title> </head> <body> <div class="row" id = "demo"> <div class="col-md-4"><h1>${h1}</h1></div> <div class="col-md-4"></div> <div class="col-md-4"></div> </div> <form action="" class="form form-horizontal responsive" id="demoform-2"> <c:forEach items="${scorelist}" var="sco"> <div class="row cl"> <label class="form-label col-3">${sco.subjectName}:</label> <div class="formControls col-5"> <input type="text" name="scoreid" id = "scoreid" value="${sco.scoreId}" style="display:none;"/> <input type="text" value = "${sco.score}" class="input-text" placeholder="請輸入${sco.subjectName}成績" name="scorelist" datatype="n1-3" nullmsg="成績不能為空,可以為零" > </div> <div class="col-4"> </div> </div> </c:forEach> <div class="row cl"> <div class="col-10 col-offset-2"> <input class="btn btn-primary" type="button" οnclick="hehe();" id = "tijiao" value=" 提交 "> </div> </div> </form> </body> <script type="text/javascript"> var list = document.getElementsByName("scorelist"); if(list.length==0){ $("input").hide(); } function hehe() { var list1 = document.getElementsByName("scorelist"); var list2 = document.getElementsByName("scoreid"); var scorelist = [list1.length]; for(var i = 0 ;i < list1.length ; i++){ scorelist[i] = [list1[i].value,list2[i].value]; } if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status == 1){ swal({title:"提交成功!",text:"您已經向伺服器了這條資訊!",type:"success"}, function () { parent.top.topManager.reloadPage(); parent.layer.closeAll(); }); }else{ swal("哦豁","提交失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","scoreadd?scorelist="+scorelist ,true); xmlhttp.send(); } </script> </html>
xsgrcjcx.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <title>課程列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">學生個人課程資訊管理表</h2></div> <div class="col-md-4"></div> </div> </div> <br/> <table class="table table-hover" id = 'table'> <tr class="info"> <th>課程編號</th> <th>課程名字</th> <th>授課老師</th> <th>課程學分</th> <th>分數</th> </tr> <c:forEach items="${scoreonelist}" var="sco"> <tr> <td>${sco.subjectId}</td> <td>${sco.subjectName}</td> <td>${sco.teacherName}</td> <td>${sco.subjectCredit}</td> <td>${sco.score}</td> </tr> </c:forEach> </table> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h1>${h1}</h1></div> <div class="col-md-4"></div> </div> <div id="page11" style="margin-top:5px; text-align:center;"></div> </body> </html>
xsyxkc.jsp <!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="//java.sun.com/jsp/jstl/core" %> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/iconfont.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/sweetalert/sweetalert.css"> <script src="<%=request.getContextPath()%>/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/lib/layer/1.9.3/layer.js"></script> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script src="<%=request.getContextPath()%>/js/sweetalert/sweetalert.min.js"></script> <title>已選課程列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="container-fluid"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"><h2 class="text-center">學生已選課程表</h2></div> <div class="col-md-4"></div> </div> </div> <br/> <table class="table table-hover"> <tr class="info"> <th>課程編號</th> <th>課程名字</th> <th>授課老師</th> <th>課程學分</th> <th>操作</th> </tr> <c:forEach items="${yxsubjectlist}" var="sbj"> <tr> <td>${sbj.subjectId}</td> <td>${sbj.subjectName}</td> <td>${sbj.teacherName}</td> <td>${sbj.subjectCredit}</td> <td> <button type="button" class="btn btn-danger btn-xs" onclick="del(${sbj.subjectId},${userbean.userId});" > <i class="iconfont"></i> 刪除本課程 </button> </td> </tr> </c:forEach> </table> </body> <script src="<%=request.getContextPath()%>/lib/laypage/1.2/laypage.js"></script> <script type="text/javascript"> function del(subjectid,studentid) { swal({ title: "您確定要刪除這條資訊嗎", text: "刪除後將無法恢復,請謹慎操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "刪除", closeOnConfirm: false }, function () { if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創建XMLHttpRequest對象 xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var a = eval("("+xmlhttp.responseText+")"); if(a.status== 1){ swal({title:"刪除成功!",text:"您已經永久刪除了這條資訊!",type:"success"}, function () { location.href = 'xsyxkc?studentId=' + '${userbean.userId}' ; }); }else{ swal("哦豁","刪除失敗,請重試!","error"); } } } ; //伺服器響應時完成相應操作 xmlhttp.open("post","yxkcdel?subjectId=" + subjectid + "&studentId=" + studentid,true); xmlhttp.send(); }); } </script> </html>
關於介面gy.jsp:
<!DOCTYPE HTML> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script src="<%=request.getContextPath()%>/js/jquery-1.8.3.js"></script> <link rel="stylesheet" href="<%=request.getContextPath()%>/font/font1/LiDeBiao-Xing3.css"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"> <title>學生列表</title> </head> <body background="<%=request.getContextPath()%>/images/010.gif"> <div class="row"> <div class="col-md-2"></div> <div class="col-md-8"> <div style='font-size: 60px;font-family:LiDeBiao-Xing3555757;margin-top:100px;' > 系統開發中。。。。。。。 </div> </div> <div class="col-md-2"></div> </div> </body> <!-- 站在巨人的肩膀上,在互聯網的胯下瘋狂輸出!<br/> ——鄒海清 --> </html>
項目截圖:
。。。。。
具體項目源碼地址:
源碼地址 : //gitee.com/z77z/StuSystem