SSM整合之---简单选课系统

简单选课系统

一.实体图

SSM整合之---简单选课系统_第1张图片

二.功能

SSM整合之---简单选课系统_第2张图片

三.代码实现

 SSM整合之---简单选课系统_第3张图片

SSM整合之---简单选课系统_第4张图片

SSM整合之---简单选课系统_第5张图片

1.SSM环境搭建

(1)pom.xml

<dependencies>
  <dependency>
    <groupId>junitgroupId>
    <artifactId>junitartifactId>
    <version>4.11version>
  dependency>
  
  
  <dependency>
    <groupId>ch.qos.logbackgroupId>
    <artifactId>logback-classicartifactId>
    <version>1.1.1version>
  dependency>

  
  <dependency>
    <groupId>mysqlgroupId>
    <artifactId>mysql-connector-javaartifactId>
    <version>5.1.37version>
    <scope>runtimescope>
  dependency>
  <dependency>
    <groupId>c3p0groupId>
    <artifactId>c3p0artifactId>
    <version>0.9.1.2version>
  dependency>

  
  <dependency>
    <groupId>org.mybatisgroupId>
    <artifactId>mybatisartifactId>
    <version>3.3.0version>
  dependency>
  <dependency>
    <groupId>org.mybatisgroupId>
    <artifactId>mybatis-springartifactId>
    <version>1.2.3version>
  dependency>

  
  <dependency>
    <groupId>taglibsgroupId>
    <artifactId>standardartifactId>
    <version>1.1.2version>
  dependency>
  <dependency>
    <groupId>javax.servletgroupId>
    <artifactId>jstlartifactId>
    <version>1.2version>
  dependency>
  <dependency>
    <groupId>com.fasterxml.jackson.coregroupId>
    <artifactId>jackson-databindartifactId>
    <version>2.5.4version>
  dependency>
  <dependency>
    <groupId>javax.servletgroupId>
    <artifactId>javax.servlet-apiartifactId>
    <version>3.1.0version>
  dependency>

  
  
  <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-coreartifactId>
    <version>4.1.7.RELEASEversion>
  dependency>
  <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-beansartifactId>
    <version>4.1.7.RELEASEversion>
  dependency>
  <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-contextartifactId>
    <version>4.1.7.RELEASEversion>
  dependency>
  
  <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-jdbcartifactId>
    <version>4.1.7.RELEASEversion>
  dependency>
  <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-txartifactId>
    <version>4.1.7.RELEASEversion>
  dependency>
  
  <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-webartifactId>
    <version>4.1.7.RELEASEversion>
  dependency>
  <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-webmvcartifactId>
    <version>4.1.7.RELEASEversion>
  dependency>
  
  <dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-testartifactId>
    <version>4.1.7.RELEASEversion>
  dependency>

  
  <dependency>
    <groupId>redis.clientsgroupId>
    <artifactId>jedisartifactId>
    <version>2.7.3version>
  dependency>
  <dependency>
    <groupId>com.dyuproject.protostuffgroupId>
    <artifactId>protostuff-coreartifactId>
    <version>1.0.8version>
  dependency>
  <dependency>
    <groupId>com.dyuproject.protostuffgroupId>
    <artifactId>protostuff-runtimeartifactId>
    <version>1.0.8version>
  dependency>
  
  <dependency>
    <groupId>commons-collectionsgroupId>
    <artifactId>commons-collectionsartifactId>
    <version>3.2version>
  dependency>
  
  <dependency>
    <groupId>aopalliancegroupId>
    <artifactId>aopallianceartifactId>
    <version>1.0version>
  dependency>
  
  <dependency>
    <groupId>org.aspectjgroupId>
    <artifactId>aspectjweaverartifactId>
    <version>1.9.2version>
  dependency>
  
  <dependency>
    <groupId>org.aspectjgroupId>
    <artifactId>aspectjrtartifactId>
    <version>1.9.3version>
  dependency>
  
  <dependency>
    <groupId>org.aspectjgroupId>
    <artifactId>aspectjweaverartifactId>
    <version>1.9.4version>
  dependency>


dependencies>

 

(2)web.xml

<web-app>

  <display-name>Archetype Created Web Applicationdisplay-name>



  

  <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>

  listener>

  

  <context-param>

    <param-name>contextConfigLocationparam-name>

    <param-value>classpath:applicationContext.xmlparam-value>

  context-param>



  



  <filter>



    <filter-name>encodingFilterfilter-name>



    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>



    <init-param>



      <param-name>encodingparam-name>



      <param-value>UTF-8param-value>



    init-param>



    <init-param>



      <param-name>forceEncodingparam-name>



      <param-value>trueparam-value>



    init-param>



  filter>



  <filter-mapping>



    <filter-name>encodingFilterfilter-name>



    <url-pattern>/*url-pattern>



  filter-mapping>



  

  <servlet>



    <servlet-name>SpringMVCservlet-name>



    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>



    <init-param>



      <param-name>contextConfigLocationparam-name>



      <param-value>classpath:springmvc.xmlparam-value>



    init-param>

    

    <load-on-startup>1load-on-startup>



  servlet>



  <servlet-mapping>



    <servlet-name>SpringMVCservlet-name>



    <url-pattern>/url-pattern>



  servlet-mapping>



web-app>

 

(3)applicationContext.xml

xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:aop="http://www.springframework.org/schema/aop"

       xmlns:mvc="http://www.springframework.org/schema/mvc"

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

   http://www.springframework.org/schema/mvc

   http://www.springframework.org/schema/mvc/spring-mvc.xsd">



    

    <context:component-scan base-package="com.ssm.dao,com.ssm.service">context:component-scan>



    

    

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

        <property name="driverClass" value="com.mysql.jdbc.Driver">property>



        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/zml03">property>



        <property name="user" value="root">property>



        <property name="password" value="root">property>

    bean>

    

    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">



        <property name="dataSource" ref="dataSource">property>

        

        <property name="mapperLocations" value="classpath:com/ssm/dao/*.xml">property>

    bean>

    

    <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">

        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean">property>

        <property name="basePackage" value="com.ssm.dao">property>

    bean>



    

    

    <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource">property>

    bean>

    

    <tx:advice id="txAdvice" transaction-manager="dataSourceTransactionManager">

        <tx:attributes>

            <tx:method name="find*" read-only="true"/>

            <tx:method name="*" isolation="DEFAULT"/>

        tx:attributes>

    tx:advice>

    

    

    

    



beans>

 

(4)springmvc.xml

xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:tx="http://www.springframework.org/schema/tx"

       xmlns:mvc="http://www.springframework.org/schema/mvc"

       xsi:schemaLocation="http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans.xsd

       http://www.springframework.org/schema/context

       http://www.springframework.org/schema/context/spring-context.xsd

       http://www.springframework.org/schema/tx

       http://www.springframework.org/schema/tx/spring-tx.xsd

       http://www.springframework.org/schema/mvc

       http://www.springframework.org/schema/mvc/spring-mvc.xsd

        ">

    

    <context:component-scan base-package="com.ssm.controller">context:component-scan>



    

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">



        



        <property name="prefix" value="/">property>



        



        <property name="suffix" value=".jsp">property>



    bean>



    

    <mvc:resources mapping="/css/**" location="/css/">mvc:resources>

    <mvc:resources mapping="/images/**" location="/images/">mvc:resources>

    <mvc:resources mapping="/js/**" location="/js/">mvc:resources>



    

    <mvc:annotation-driven/>

    <mvc:default-servlet-handler/>

beans>

 

2.entity

(1)Course.java

package com.ssm.entity;



public class Course {

    private String cno;

    private String cname;

    private int ctime;

    private int ccredit;

    private String tno;



    public String getCno() {

        return cno;

    }



    public void setCno(String cno) {

        this.cno = cno;

    }



    public String getCname() {

        return cname;

    }



    public void setCname(String cname) {

        this.cname = cname;

    }



    public int getCtime() {

        return ctime;

    }



    public void setCtime(int ctime) {

        this.ctime = ctime;

    }



    public int getCcredit() {

        return ccredit;

    }



    public void setCcredit(int ccredit) {

        this.ccredit = ccredit;

    }



    public String getTno() {

        return tno;

    }



    public void setTno(String tno) {

        this.tno = tno;

    }



    @Override

    public String toString() {

        return "Course{" +

                "cno='" + cno + '\'' +

                ", cname='" + cname + '\'' +

                ", ctime=" + ctime +

                ", ccredit=" + ccredit +

                ", tno='" + tno + '\'' +

                '}';

    }

}

 

(2)Dective.java

package com.ssm.entity;



public class Dective {

    private int dno;

    private String sno;

    private String cno;

    private double achievement;



    public int getDno() {

        return dno;

    }



    public void setDno(int dno) {

        this.dno = dno;

    }



    public String getSno() {

        return sno;

    }



    public void setSno(String sno) {

        this.sno = sno;

    }



    public String getCno() {

        return cno;

    }



    public void setCno(String cno) {

        this.cno = cno;

    }



    public double getAchievement() {

        return achievement;

    }



    public void setAchievement(double achievement) {

        this.achievement = achievement;

    }



    @Override

    public String toString() {

        return "Dective{" +

                "dno=" + dno +

                ", sno='" + sno + '\'' +

                ", cno='" + cno + '\'' +

                ", achievement=" + achievement +

                '}';

    }

}

 

(3)Student.java

package com.ssm.entity;



public class Student {

    private String sno;

    private String sname;

    private String ssex;

    private String spassword;



    public String getSno() {

        return sno;

    }



    public void setSno(String sno) {

        this.sno = sno;

    }



    public String getSname() {

        return sname;

    }



    public void setSname(String sname) {

        this.sname = sname;

    }



    public String getSsex() {

        return ssex;

    }



    public void setSsex(String ssex) {

        this.ssex = ssex;

    }



    public String getSpassword() {

        return spassword;

    }



    public void setSpassword(String spassword) {

        this.spassword = spassword;

    }



    @Override

    public String toString() {

        return "Student{" +

                "sno='" + sno + '\'' +

                ", sname='" + sname + '\'' +

                ", ssex='" + ssex + '\'' +

                ", spassword='" + spassword + '\'' +

                '}';

    }

}

 

(4)Teacher.java

package com.ssm.entity;



public class Teacher {

    private String tno;

    private String tname;

    private String tsex;

    private String tpassword;

    private String ttitle;



    public String getTno() {

        return tno;

    }



    public void setTno(String tno) {

        this.tno = tno;

    }



    public String getTname() {

        return tname;

    }



    public void setTname(String tname) {

        this.tname = tname;

    }



    public String getTsex() {

        return tsex;

    }



    public void setTsex(String tsex) {

        this.tsex = tsex;

    }



    public String getTpassword() {

        return tpassword;

    }



    public void setTpassword(String tpassword) {

        this.tpassword = tpassword;

    }



    public String getTtitle() {

        return ttitle;

    }



    public void setTtitle(String ttitle) {

        this.ttitle = ttitle;

    }



    @Override

    public String toString() {

        return "Teacher{" +

                "tno='" + tno + '\'' +

                ", tname='" + tname + '\'' +

                ", tsex='" + tsex + '\'' +

                ", tpassword='" + tpassword + '\'' +

                ", ttitle='" + ttitle + '\'' +

                '}';

    }

}

 

3.dao接口

(1)CourseDao.java

package com.ssm.dao;



import com.ssm.entity.Course;

import com.ssm.view.courseVo;

import org.mybatis.spring.annotation.MapperScan;

import org.springframework.stereotype.Repository;



import java.util.List;



@Repository

public interface CourseDao {

    //查询所有课程信息

    public List selectCourse();

    //查看可选的所有课程

    public List selectAllCourse();

}

 

(2)DectiveDao.java

package com.ssm.dao;



import com.ssm.entity.Dective;

import com.ssm.entity.Student;

import com.ssm.view.DectiveVo;

import com.ssm.view.StudentVo;

import com.ssm.view.courseVo;

import org.apache.ibatis.annotations.Param;

import org.springframework.stereotype.Repository;



import java.util.List;



@Repository

public interface DectiveDao {

    //插入选课记录

    public void insertDective(Dective dective);

    //学生查询自己的选课记录

    public List selectMy(String sno);

    //删除选课记录

    public void deleteDective(Dective dective);

    //查询成绩

    public List selectGrade(String sno);

    //查询选择了某个课程的所有学生信息

    public List courseStudent(String cname);

    //录入成绩

    public void grade(@Param("sno") String sno,@Param("cno") String cno,@Param("achievement") double achievement);



 }

 

(3)StudentDao.java

package com.ssm.dao;



import com.ssm.entity.Student;

import org.apache.ibatis.annotations.Param;

import org.springframework.stereotype.Repository;



@Repository

public interface StudentDao {

    //根据sno查找用户的密码,检测登录

    public String selectSpassword(String sno);

    //根据sno查询学生信息

    public Student selectone(String sno);

    //修改学生信息

    public void stuUpdate(@Param("spassword") String spassword,@Param("sno") String sno);

}

 

(4)TeacherDao.java

package com.ssm.dao;



import com.ssm.entity.Teacher;

import org.apache.ibatis.annotations.Param;

import org.springframework.stereotype.Repository;



import java.util.List;



@Repository

public interface TeacherDao {

    //根据tno查找用户的密码,检测登录

    public String selectTpassword(String tno);

    //根据tno查询老师信息

    public Teacher selectte(String tno);

    //修改老师信息

    public void updatete(@Param("tpassword") String tpassword,@Param("tno") String tno);

    //查询某个老师所教的所有课程

    public List selectMyCourse(String tno);

}

 

4.dao映射文件

(1)CourseDao.xml

xml version="1.0" encoding="UTF-8" ?>



DOCTYPEmapper



        PUBLIC"-//mybatis.org//DTD Mapper 3.0//EN"



        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.ssm.dao.CourseDao">

    <select id="selectCourse" resultType="com.ssm.entity.Course">

       select * from course

    select>



     

    <select id="selectAllCourse" resultType="com.ssm.view.courseVo">

        select c.*,t.tname from course c,teacher t where c.tno = t.tno

    select>



mapper>

 

(2)DectiveDao.xml

xml version="1.0" encoding="UTF-8" ?>



        DOCTYPEmapper



                PUBLIC"-//mybatis.org//DTD Mapper 3.0//EN"



                "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.ssm.dao.DectiveDao">

        

        <insert id="insertDective" parameterType="com.ssm.entity.Dective">

                insert into dective(sno,cno) values(#{sno},#{cno})

        insert>

        

        <delete id="deleteDective"  parameterType="com.ssm.entity.Dective">

                delete from dective where cno=#{cno} and sno=#{sno}

        delete>

        

        <select id="selectMy" parameterType="String" resultType="com.ssm.view.courseVo">

                select c.*,t.tname from dective d LEFT OUTER JOIN course c on d.cno=c.cno LEFT OUTER JOIN teacher t on c.tno=t.tno where d.sno=#{sno}

        select>

        

        <select id="selectGrade" parameterType="String" resultType="com.ssm.view.DectiveVo">

                select achievement ,c.cname from dective d LEFT OUTER JOIN course c on d.cno=c.cno where sno=#{sno}

        select>

        

        <select id="courseStudent" parameterType="String" resultType="com.ssm.view.StudentVo">

                select s.* ,c.cno,d.achievement from course c LEFT OUTER JOIN dective d on c.cno=d.cno LEFT OUTER JOIN student s on s.sno=d.sno where c.cname=#{cname}

        select>

        

        <update id="grade" parameterType="com.ssm.entity.Dective">

                update dective set achievement=#{achievement} where sno=#{sno} and cno=#{cno}

        update>



mapper>

 

(3)StudentDao.xml

xml version="1.0" encoding="UTF-8" ?>



DOCTYPEmapper



        PUBLIC"-//mybatis.org//DTD Mapper 3.0//EN"



        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.ssm.dao.StudentDao">

    

    <select id="selectSpassword" resultType="String">

        select spassword from student where sno=#{sno}

    select>

    

    <select id="selectone" resultType="com.ssm.entity.Student" parameterType="String">

        select * from student where sno=#{sno}

    select>

    

    <update id="stuUpdate" parameterType="String">

        update student set spassword=#{spassword} where sno=#{sno}

    update>

mapper>

 

(4)TeacherDao.xml

xml version="1.0" encoding="UTF-8" ?>



DOCTYPEmapper



        PUBLIC"-//mybatis.org//DTD Mapper 3.0//EN"



        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.ssm.dao.TeacherDao">

    

 <select id="selectTpassword" resultType="String">

     select tpassword from teacher where tno=#{tno}

 select>

    <select id="selectte" parameterType="String" resultType="com.ssm.entity.Teacher">

        select * from teacher where tno=#{tno}

    select>

    

    <update id="updatete" parameterType="String">

        update teacher set tpassword=#{tpassword} where tno=#{tno}

    update>

    

    <select id="selectMyCourse" resultType="String" parameterType="String">

        select cname from course where tno=#{tno}

    select>

mapper>

 

5.service接口

(1)CourseService.java

package com.ssm.service;



import com.ssm.entity.Course;

import com.ssm.view.courseVo;



import java.util.List;



public interface CourseService {

    //查询所有课程信息

    public List selectCourse();

    //查看可选的所有课程

    public List selectAllCourse();

}

 

(2)DectiveService.java

package com.ssm.service;



import com.ssm.entity.Dective;

import com.ssm.entity.Student;

import com.ssm.view.DectiveVo;

import com.ssm.view.StudentVo;

import com.ssm.view.courseVo;

import org.apache.ibatis.annotations.Param;



import java.util.List;



public interface DectiveService {

    //插入选课记录

    public void insertDective(Dective dective);

    //学生查询自己的选课记录

    public List selectMy(String sno);

    //删除选课记录

    public void deleteDective(Dective dective);

    //查询成绩

    public List selectGrade(String sno);

    //查询选择了某个课程的所有学生信息

    public List courseStudent(String cname);

    //录入成绩

    public void grade(String sno, String cno,double achievement);

}

 

(3)StudentService.java

package com.ssm.service;



import com.ssm.entity.Student;



public interface StudentService {

    //根据sno查找用户的密码,检测登录

    public String selectSpassword(String sno);

    //根据sno查询学生信息

    public Student selectone(String sno);

    //修改学生信息

    public void stuUpdate(String spassword,String sno);

}

 

(4)TeacherService.java

package com.ssm.service;



import com.ssm.entity.Teacher;



import java.util.List;



public interface TeacherService {

    //根据tno查找用户的密码,检测登录

    public String selectTpassword(String tno);

    //根据tno查询老师信息

    public Teacher selectte(String tno);

    //修改老师信息

    public void updatete(String tpassword,String tno);

    //查询某个老师所教的所有课程

    public List selectMyCourse(String tno);

}

 

6.service实现类

(1)CourseServiceImpl.java

package com.ssm.service.Impl;



import com.ssm.dao.CourseDao;

import com.ssm.entity.Course;

import com.ssm.service.CourseService;

import com.ssm.view.courseVo;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;



import java.util.List;



@Service

public class CourseServiceImpl implements CourseService {

    @Autowired

    private CourseDao courseDao;

    @Override

    public List selectCourse() {

        return courseDao.selectCourse();

    }



    @Override

    public List selectAllCourse() {

        return courseDao.selectAllCourse();

    }

}

 

(2)DectiveServiceImpl.java

package com.ssm.service.Impl;



import com.ssm.dao.DectiveDao;

import com.ssm.entity.Dective;

import com.ssm.entity.Student;

import com.ssm.service.DectiveService;

import com.ssm.view.DectiveVo;

import com.ssm.view.StudentVo;

import com.ssm.view.courseVo;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;



import java.util.List;



@Service

public class DectiveServiceImpl implements DectiveService {

    @Autowired

    private DectiveDao dectiveDao;

    //插入选课记录

    @Override

    public void insertDective(Dective dective) {

        dectiveDao.insertDective(dective);

    }

    //学生查询自己的选课记录

    @Override

    public List selectMy(String sno) {

        return dectiveDao.selectMy(sno);

    }

    //删除选课记录

    @Override

    public void deleteDective(Dective dective) {

        dectiveDao.deleteDective(dective);

    }



    @Override

    public List selectGrade(String sno) {

        return dectiveDao.selectGrade(sno);

    }



    @Override

    public List courseStudent(String cname) {

        return dectiveDao.courseStudent(cname);

    }



    @Override

    public void grade(String sno, String cno,double achievement) {

        dectiveDao.grade(sno,cno,achievement);

    }



}

 

(3)StudentServiceImpl.java

package com.ssm.service.Impl;



import com.ssm.dao.StudentDao;

import com.ssm.entity.Student;

import com.ssm.service.StudentService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;



@Service

public class StudentServiceImpl implements StudentService {

    @Autowired

    private StudentDao studentDao;



    @Override

    public String selectSpassword(String sno) {

        return studentDao.selectSpassword(sno);

    }



    @Override

    public Student selectone(String sno) {

        return studentDao.selectone(sno);

    }



    @Override

    public void stuUpdate(String spassword,String sno) {

        studentDao.stuUpdate(spassword,sno);

    }

}

 

(4)TeacherServiceImpl.java

package com.ssm.service.Impl;



import com.ssm.dao.TeacherDao;

import com.ssm.entity.Teacher;

import com.ssm.service.TeacherService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;



import java.util.List;



@Service

public class TeacherServiceImpl implements TeacherService {

    @Autowired

    private TeacherDao teacherDao;

    @Override

    public String selectTpassword(String tno) {

        return teacherDao.selectTpassword(tno);

    }



    @Override

    public Teacher selectte(String tno) {

        System.out.println(teacherDao.selectte(tno));

        return teacherDao.selectte(tno);

    }



    @Override

    public void updatete(String tpassword, String tno) {

        teacherDao.updatete(tpassword,tno);

    }



    @Override

    public List selectMyCourse(String tno) {

        return teacherDao.selectMyCourse(tno);

    }

}

 

7.controller

(1)CourseController.java

package com.ssm.controller;



import com.ssm.service.Impl.CourseServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;



@Controller

@RequestMapping("/courseController")

public class CourseController {

    @Autowired

    private CourseServiceImpl courseService;

    @RequestMapping("/selectCourse")

    public ModelAndView selectCourse(){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("list",courseService.selectCourse());

        modelAndView.setViewName("list");

        return modelAndView;

    }

    //查询所有课程信息

    @RequestMapping("/selectAllCourse")

    public ModelAndView selectAllCourse(){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("courseVo",courseService.selectAllCourse());

        modelAndView.setViewName("courseVo");

        return modelAndView;

    }

    //查询所有课程信息

    @RequestMapping("/selectAll")

    public ModelAndView selectAll(){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("lookCourse",courseService.selectAllCourse());

        modelAndView.setViewName("lookCourse");

        return modelAndView;

    }

}

 

(2)DectiveController.java

package com.ssm.controller;



import com.ssm.entity.Dective;

import com.ssm.service.Impl.DectiveServiceImpl;

import com.ssm.view.DectiveList;

import com.ssm.view.DectiveVo;

import com.ssm.view.StudentVo;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;



import javax.servlet.http.HttpSession;

import java.util.List;



@Controller

@RequestMapping("/dectiveController")

public class DectiveController {

    @Autowired

    private DectiveServiceImpl dectiveService;

    //插入选课记录

    @RequestMapping("/insertDective")

    public String insertDective(HttpSession httpSession,String cno){

        Dective dective=new Dective();

        dective.setCno(cno);

        dective.setSno((String)httpSession.getAttribute("sno"));

        System.out.println("cno:"+cno+",sno:"+httpSession.getAttribute("sno"));

        dectiveService.insertDective(dective);

        return "redirect:/courseController/selectAllCourse";

    }

    //查询自己选过的课程

    @RequestMapping("/selectMy")

    public ModelAndView selectMy(HttpSession httpSession){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("selectMy",dectiveService.selectMy((String)httpSession.getAttribute("sno")));

        modelAndView.setViewName("myDective");

        return modelAndView;

    }

    //删除选课记录

    @RequestMapping("/deleteDective")

    public String deleteDective(HttpSession httpSession,String cno){

        Dective dective=new Dective();

        dective.setCno(cno);

        dective.setSno((String)httpSession.getAttribute("sno"));

        dectiveService.deleteDective(dective);

        return "redirect:selectMy";

    }

    //查询成绩

    @RequestMapping("selectGrade")

    public ModelAndView selectGrade(HttpSession session){

        ModelAndView modelAndView=new ModelAndView();

        List list=dectiveService.selectGrade((String)session.getAttribute("sno"));

        System.out.println(list);

        modelAndView.addObject("selectGrade",list);



        modelAndView.setViewName("myGrade");

        return modelAndView;

    }

    //查询选择了某个课程的所有学生信息

    @RequestMapping("/courseStudent")

    public ModelAndView courseStudent(String cname){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("student",dectiveService.courseStudent(cname));

        modelAndView.setViewName("courseStudent");

        return modelAndView;

    }

    //查询选择某个课程的所有学生

    @RequestMapping("/courseAllStudent")

    public ModelAndView courseAllStudent(String cname){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("studentVo",dectiveService.courseStudent(cname));

        modelAndView.setViewName("grade");

        return modelAndView;

    }

    //录入成绩

    @RequestMapping("/grade")

    public String grade(DectiveList dectiveList){

        System.out.println(dectiveList);

        for(Dective dective:dectiveList.getDectiveList()){

            String sno=dective.getSno();

            String cno=dective.getCno();

            double achievement=dective.getAchievement();

            dectiveService.grade(sno,cno,achievement);

        }

        return "redirect:/teacherController/selectAllCourse";

    }

}

 

(3)StudentController.java

package com.ssm.controller;



import com.ssm.service.Impl.StudentServiceImpl;

import org.omg.CORBA.Request;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.http.HttpRequest;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;



import javax.servlet.http.HttpSession;



@Controller

@RequestMapping("/studentController")

public class StudentController {

    @Autowired

    private StudentServiceImpl studentService;

    //检测登录

    @RequestMapping("/selectSpassword")

    public String selectSpassword(HttpSession session, String sno, String password){

        String pwd=studentService.selectSpassword(sno);

        System.out.println(pwd);

        if(pwd.equals(password)){

            session.setAttribute("sno",sno);

            return "redirect:selectone";

        }else{

            return "index";

        }



    }

    //根据sno查询信息

    @RequestMapping("/selectone")

    public ModelAndView selectone(HttpSession session){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("student",studentService.selectone((String)session.getAttribute("sno")));

        modelAndView.setViewName("student");

        return modelAndView;

    }

    //根据sno查询信息

    @RequestMapping("/selectstu")

    public ModelAndView selectstu(HttpSession session){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("student",studentService.selectone((String)session.getAttribute("sno")));

        modelAndView.setViewName("studentUpdate");

        return modelAndView;

    }

    //修改学生信息

    @RequestMapping("stuUpdate")

    public String stuUpdate(HttpSession session,String spassword){

        System.out.println("密   码:  "+spassword);

        studentService.stuUpdate(spassword,(String)session.getAttribute("sno"));



        return "redirect:selectone";

    }



}

 

(4)TeacherController.java

package com.ssm.controller;



import com.ssm.entity.Teacher;

import com.ssm.service.Impl.TeacherServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;



import javax.servlet.http.HttpSession;



@Controller

@RequestMapping("/teacherController")

public class TeacherController {

    @Autowired

    private TeacherServiceImpl teacherService;

    //老师登录

    @RequestMapping("/selectTpassword")

    public String selectTpassword(HttpSession session,String tno ,String tpassword){

        String pwd=teacherService.selectTpassword(tno);

        System.out.println(pwd);

        if(pwd.equals(tpassword)){

            session.setAttribute("tno", tno);

            return "redirect:selectte";

        }else{

            return "index";

        }

    }

    //根据tno查询老师信息

    @RequestMapping("/selectte")

    public ModelAndView selectte(HttpSession session){

        ModelAndView modelAndView=new ModelAndView();

        String t=(String)session.getAttribute("tno");

        Teacher te=teacherService.selectte(t);

        modelAndView.addObject("teacher",te);

        System.out.println(te);

        modelAndView.setViewName("teacher");

        return modelAndView;

    }

    @RequestMapping("/selectone")

    public ModelAndView selectone(HttpSession session){

        ModelAndView modelAndView=new ModelAndView();

        String t=(String)session.getAttribute("tno");

        Teacher te=teacherService.selectte(t);

        modelAndView.addObject("teacher",te);

        System.out.println(te);

        modelAndView.setViewName("teacherUpdate");

        return modelAndView;

    }

    //修改老师信息

    @RequestMapping("/updatete")

    public String updatete(HttpSession session,String tpassword){

        teacherService.updatete(tpassword,(String)session.getAttribute("tno"));

        return "redirect:selectte";

    }

    //查询老师的所有课程

    @RequestMapping("/selectMyCourse")

    public ModelAndView selectMyCourse(HttpSession session){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("cname",teacherService.selectMyCourse((String)session.getAttribute("tno")));

        modelAndView.setViewName("teacherCourse");

        return modelAndView;

    }

    //查询老师的所有课程

    @RequestMapping("/selectAllCourse")

    public ModelAndView selectAllCourse(HttpSession session){

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("cname",teacherService.selectMyCourse((String)session.getAttribute("tno")));

        modelAndView.setViewName("courseAll");

        return modelAndView;

    }
}

 

8.view

(1)CourseVo.java

package com.ssm.view;



public class courseVo {



    private String cno;



    private String cname;



    private int ctime;



    private int tno;



    private String tname;





    public courseVo() {

    }



    public String getCno() {

        return cno;

    }



    public void setCno(String cno) {

        this.cno = cno;

    }



    public String getCname() {

        return cname;

    }



    public void setCname(String cname) {

        this.cname = cname;

    }



    public int getCtime() {

        return ctime;

    }



    public void setCtime(int ctime) {

        this.ctime = ctime;

    }



    public int getTno() {

        return tno;

    }



    public void setTno(int tno) {

        this.tno = tno;

    }



    public String getTname() {

        return tname;

    }



    public void setTname(String tname) {

        this.tname = tname;

    }



    public courseVo(String cno, String cname, int ctime, int tno, String tname) {

        this.cno = cno;

        this.cname = cname;

        this.ctime = ctime;

        this.tno = tno;

        this.tname = tname;

    }



    @Override

    public String toString() {

        return "courseVo{" +

                "cno='" + cno + '\'' +

                ", cname='" + cname + '\'' +

                ", ctime=" + ctime +

                ", tno=" + tno +

                ", tname='" + tname + '\'' +

                '}';

    }

}

 

(2)DectiveList.java

package com.ssm.view;



import com.ssm.entity.Dective;



import java.util.List;



public class DectiveList {

    private List dectiveList;



    public List getDectiveList() {

        return dectiveList;

    }



    public void setDectiveList(List dectiveList) {

        this.dectiveList = dectiveList;

    }



    @Override

    public String toString() {

        return "DectiveList{" +

                "dectiveList=" + dectiveList +

                '}';

    }

}

 

(3)DectiveVo.java

package com.ssm.view;



public class DectiveVo {

    private String cname;

    private double achievement;



    public String getCname() {

        return cname;

    }



    public void setCname(String cname) {

        this.cname = cname;

    }



    public double getAchievement() {

        return achievement;

    }



    public void setAchievement(double achievement) {

        this.achievement = achievement;

    }



    @Override

    public String toString() {

        return "DectiveVo1{" +

                "cname='" + cname + '\'' +

                ", achievement=" + achievement +

                '}';

    }

}

 

(4)StudentVo.java

package com.ssm.view;



public class StudentVo {



    private String sno;

    private String sname;

    private String ssex;

    private String spassword;

    private String cno;

    private double achievement;



    public String getSno() {

        return sno;

    }



    public void setSno(String sno) {

        this.sno = sno;

    }



    public String getSname() {

        return sname;

    }



    public void setSname(String sname) {

        this.sname = sname;

    }



    public String getSsex() {

        return ssex;

    }



    public void setSsex(String ssex) {

        this.ssex = ssex;

    }



    public String getSpassword() {

        return spassword;

    }



    public void setSpassword(String spassword) {

        this.spassword = spassword;

    }



    public String getCno() {

        return cno;

    }



    public void setCno(String cno) {

        this.cno = cno;

    }



    public double getAchievement() {

        return achievement;

    }



    public void setAchievement(double achievement) {

        this.achievement = achievement;

    }



    @Override

    public String toString() {

        return "StudentVo{" +

                "sno='" + sno + '\'' +

                ", sname='" + sname + '\'' +

                ", ssex='" + ssex + '\'' +

                ", spassword='" + spassword + '\'' +

                ", cno='" + cno + '\'' +

                ", achievement=" + achievement +

                '}';

    }

}

 

9.jsp页面

(1)courseAll.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

<c:forEach items="${cname}" var="name">

    <a href="/dectiveController/courseAllStudent?cname=${name}">${name}a>         

c:forEach>

body>

html>

 

(2)courseStudent.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

<table>

    <tr>

        <td>学号td>

        <td>姓名td>

    tr>

    <c:forEach items="${student}" var="Student">

        <tr>

            <td>${Student.sno}td>

            <td>${Student.sname}td>

        tr>

    c:forEach>

table>

body>

html>

 

(3)courseVo.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

<form>

    <table>

        <tr>

            <td>课程编号td>

            <td>课程名称td>

            <td>课时td>

            <td>教师编号td>

            <td>教师姓名td>

            <td>td>

        tr>

        <c:forEach items="${courseVo}" var="CourseVo">

            <tr>

                <td>${CourseVo.cno}td>

                <td>${CourseVo.cname}td>

                <td>${CourseVo.ctime}td>

                <td>${CourseVo.tno}td>

                <td>${CourseVo.tname}td>

                <td><a href="/dectiveController/insertDective?cno=${CourseVo.cno}">选课a> td>

            tr>

        c:forEach>

    table>

form>

body>

html>

 

(4)grade.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

<%! int i=-1; %>

<form action="/dectiveController/grade" method="post">

<table>

    <tr>

        <td>课程编号td>

        <td>学号td>

        <td>姓名td>

        <td>成绩td>

    tr>

    <c:forEach items="${studentVo}" var="Student">

        <% i=i+1;%>

        <tr>

            <td><input type="text" name="dectiveList[<%=i%>].cno" value="${Student.cno}" readonly="readonly">td>

            <td><input type="text" name="dectiveList[<%=i%>].sno" value="${Student.sno}" readonly="readonly">td>

            <td><input type="text" name="sname" value="${Student.sname}" readonly="readonly">td>

            <td><input type="text" name="dectiveList[<%=i%>].achievement" value="${Student.achievement}" >td>

        tr>

    c:forEach>

table>

<input type="submit">

form>

body>

html>

 

(5)index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>

<head>

    <title>Titletitle>

head>

<body>

学生<a href="teacherlogin.jsp">老师a>

<form action="studentController/selectSpassword" method="post">

    学号:<input type="text" name="sno">

    密码:<input type="text" name="password">

    <input type="submit" >

form>

body>

html>

 

(6)list.jsp

<%--

  Created by IntelliJ IDEA.

  User: Administrator

  Date: 2019/8/17 0017

  Time: 上午 10:44

  To change this template use File | Settings | File Templates.

--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

${list}

<table>

<c:forEach items="${list2}" var="CourseVo">



    <tr>



        <td>${CourseVo.cno}td>

        <td>${CourseVo.cname}td>

        <td>${CourseVo.ctime}td>

        <td>${CourseVo.tno}td>

        <td>${CourseVo.tname}td>

        <td>td>

    tr>



c:forEach>

table>

body>

html>

 

(7)lookCourse.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

<table>

    <tr>

        <td>课程编号td>

        <td>课程名称td>

        <td>课时td>

        <td>教师编号td>

        <td>教师姓名td>

    tr>

    <c:forEach items="${lookCourse}" var="CourseVo">

        <tr>

            <td>${CourseVo.cno}td>

            <td>${CourseVo.cname}td>

            <td>${CourseVo.ctime}td>

            <td>${CourseVo.tno}td>

            <td>${CourseVo.tname}td>



        tr>

    c:forEach>

table>

body>

html>

 

(8)myDective.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

<form>

    <table>

        <tr>

            <td>课程编号td>

            <td>课程名称td>

            <td>课时td>

            <td>教师编号td>

            <td>教师姓名td>

            <td>td>

        tr>

        <c:forEach items="${selectMy}" var="CourseVo">

            <tr>

                <td>${CourseVo.cno}td>

                <td>${CourseVo.cname}td>

                <td>${CourseVo.ctime}td>

                <td>${CourseVo.tno}td>

                <td>${CourseVo.tname}td>

                <td><a href="/dectiveController/deleteDective?cno=${CourseVo.cno}">删除a> td>

            tr>

        c:forEach>

    table>

form>

body>

html>

 

(9)myGrade.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

<form>

    <table>

        <tr>

            <td>课程名称td>

            <td>成绩td>



        tr>

        <c:forEach items="${selectGrade}" var="DectiveVo">

            <tr>

                <td>${DectiveVo.cname}td>

                <td>${DectiveVo.achievement}td>

            tr>

        c:forEach>

    table>

form>

body>

html>

 

(10)student.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>



<html>

<head>

    <title>Titletitle>

head>



<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>JSP Pagetitle>

    head>

    <body>

    <a href="/courseController/selectAllCourse">选课a><br>

    <a href="/dectiveController/selectMy">查询已选课程a><br>

    <a href="/dectiveController/selectGrade">查询成绩a><br>

    <a href="/studentController/selectstu">修改信息a>

    <table>

        <tr>

            <td>学号td>

            <td>${student.sno}td>

        tr>

        <tr>

            <td>姓名td>

            <td>${student.sname}td>

        tr>

        <tr>

            <td>性别td>

            <td>${student.ssex}td>

        tr>

        <tr>

            <td>密码td>

            <td>${student.spassword}td>

        tr>



    table>

   body>

html>

 

(11)studentUpdate.jsp

<%@page contentType="text/html"%>

<%@page pageEncoding="UTF-8"%>

DOCTYPE html>

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>JSP Pagetitle>

    head>

    <body>

    <form action="/studentController/stuUpdate" method="post">

        <table>

            <tr>

                <td>学号td>

                <td><input  type="text" value="${student.sno}" readonly="readonly">td>

            tr>

            <tr>

                <td>姓名td>

                <td><input  type="text" value="${student.sname}" readonly="readonly">td>

            tr>

            <tr>

                <td>登录密码td>

                <td><input  type="text" name="spassword" value="${student.spassword}">td>

            tr>

        table>

        <input type="submit">

    form>

   body>

html>

 

(12)teacher.jsp

<%@page contentType="text/html"%>

<%@page pageEncoding="UTF-8"%>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>



DOCTYPE html>

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>JSP Pagetitle>

    head>

    <body>

       <a href="/teacherController/selectone">修改a><br>

      <a href="/courseController/selectAll">查询课程信息a>a><br>

      <a href="/teacherController/selectMyCourse">查询学生选课信息a>a><br>

      <a href="/teacherController/selectAllCourse">录入成绩a>a><br>

       <table>

          <tr>

             <td>教师编号:td>

             <td>${teacher.tno}td>

          tr>

          <tr>

             <td>教师姓名:td>

             <td>${teacher.tname}td>

          tr>

          <tr>

             <td>登录密码:td>

             <td>${teacher.tpassword}td>

          tr>

       table>

       

   body>

html>

 

(13)teacherCourse.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>

<head>

    <title>Titletitle>

head>

<body>

<c:forEach items="${cname}" var="name">

    <a href="/dectiveController/courseStudent?cname=${name}">${name}a>         

c:forEach>

body>

html>

 

(14)teacherlogin.jsp

<%@page contentType="text/html"%>

<%@page pageEncoding="UTF-8"%>

DOCTYPE html>

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>JSP Pagetitle>

    head>

    <body>

       <a href="index.jsp">学生a>老师

       <form action="teacherController/selectTpassword" method="post">

    教师编号:<input type="text" name="tno">

    密码:<input type="text" name="tpassword">

    <input type="submit"/>

        form>

    body>

html>

 

(15)teacherUpdate.jsp

<%@page contentType="text/html"%>

<%@page pageEncoding="UTF-8"%>

DOCTYPE html>

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>JSP Pagetitle>

    head>

    <body>

       <form action="/teacherController/updatete" method="post">

       <table>

          <tr>

             <td>教师编号td>

             <td><input  type="text" value="${teacher.tno}" readonly="readonly">td>

          tr>

          <tr>

             <td>教师姓名td>

             <td><input  type="text" value="${teacher.tname}" readonly="readonly">td>

          tr>

          <tr>

             <td>登录密码td>

             <td><input  type="text" name="tpassword" value="${teacher.tpassword}">td>

          tr>

       table>

       <input type="submit">

       form>

   body>

html>

 

 
=========================demo21==========================

你可能感兴趣的:(SSM整合之---简单选课系统)