第二阶段:高校学生选课系统,重要代码。及编程思想讲解

该系统我采用的是java(Spring+SpringMVC+MyBatis)架构,前端使用的是vuejs。vue负责前端,ssm负责后端,分工明确,思路清晰,维护简单。

为什么我会选择用ssm框架来开发,理由如下:

通过Spring的IOC特性,将对象之间的依赖关系交给了Spring控制,方便解耦,简化了开发,使得代码复用,可维护性大幅度提升
通过Spring的AOP特性,对重复模块进行集中,实现事务,日志,权限的控制,aop提供切面编程,同样的增强了生产力

SpringMVC是使用了MVC设计思想的轻量级web框架,对web层进行解耦,使我的开发更简洁与Spring无缝衔接

数据库的操作(sql)采用xml文件配置,解除了sql和代码的耦合

提供映射标签,支持对象和和数据库orm字段关系的映射,支持对象关系映射标签,支持对象关系的组建,提供了xml标签,支持动态的sql

SSM是WEB应用框架,涵盖整个应用层,我这个项目比较小,用ssm框架开发是最好的,轻量级,速度快,效率高。

这是我创建的基本的ssm框架, 其中Spring 和 mybatis整合,连接数据库,进行Junit测试

虽然我在个程序里小用了jsp, 但是我主要是采用动静分离,单独运用vue技术,我可以配置到服务器,把服务器上的mysql接入到ssm项目中,把服务器域名映射的ip接入到vue项目中,这样来运行整个项目。

配置web.xml文件

 配置的spring-mvc的Servlet就是为了完成SpringMVC+MAVEN的整合

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

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!--
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
-->
<!--路由配置-->
<!--<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>-->


<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>Set-Cookie</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>



<!--注册spring容器-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-application.xml</param-value>
</context-param>

<!-- 配置请求过滤器,编码格式设为UTF-8,避免中文乱码-->
<filter>
<filter-name>encode</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<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>

<!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<filter-mapping>
<filter-name>encode</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!--注册springMVC容器(前端控制器)-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<!--识别所有后缀为.html的请求.html-->
<servlet-name>springmvc</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>


<!-- log4j配置,文件路径,因为是跟随项目启动 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>


<!-- 配置SESSION超时,单位是分钟 -->
<session-config>
<session-timeout>60</session-timeout>
<!-- Disables URL-based sessions (no more 'jsessionid' in the URL using Tomcat) -->
<tracking-mode>COOKIE</tracking-mode>
</session-config>



</web-app>
然后就是最重要的数据库文件的创建,和本地数据库表的创建
/*
Navicat Premium Data Transfer

Source Server : 本地
Source Server Type : MySQL
Source Server Version : 50560
Source Host : localhost:3306
Source Schema : ssm

Target Server Type : MySQL
Target Server Version : 50560
File Encoding : 65001

Date: 17/04/2019 14:04:25
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for banji
-- ----------------------------
DROP TABLE IF EXISTS `banji`;
CREATE TABLE `banji` (
`bjcode` int(22) NOT NULL AUTO_INCREMENT,
`bjname` varchar(22) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`bjgrade` varchar(22) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`bjcode`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

-- ----------------------------
-- Records of banji
-- ----------------------------
INSERT INTO `banji` VALUES (1, '五班', '二年级');
INSERT INTO `banji` VALUES (2, '三班', '四年级');
INSERT INTO `banji` VALUES (5, '六班', '五年级');
INSERT INTO `banji` VALUES (6, '七班', '一年级');

-- ----------------------------
-- Table structure for course
-- ----------------------------
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (
`ID` int(22) NOT NULL,
`CouName` varchar(22) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

-- ----------------------------
-- Records of course
-- ----------------------------
INSERT INTO `course` VALUES (1, '语文');
INSERT INTO `course` VALUES (2, '数学');
INSERT INTO `course` VALUES (3, '英语');
INSERT INTO `course` VALUES (4, '地理');
INSERT INTO `course` VALUES (5, '政治');
INSERT INTO `course` VALUES (6, '历史');
INSERT INTO `course` VALUES (7, '化学');
INSERT INTO `course` VALUES (8, '物理');

-- ----------------------------
-- Table structure for sc
-- ----------------------------
DROP TABLE IF EXISTS `sc`;
CREATE TABLE `sc` (
`Sid` int(22) NULL DEFAULT NULL,
`Cid` int(22) NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

-- ----------------------------
-- Records of sc
-- ----------------------------
INSERT INTO `sc` VALUES (2, 2);
INSERT INTO `sc` VALUES (8, 1);
INSERT INTO `sc` VALUES (8, 2);
INSERT INTO `sc` VALUES (8, 5);
INSERT INTO `sc` VALUES (8, 6);
INSERT INTO `sc` VALUES (2, 3);
INSERT INTO `sc` VALUES (2, 5);
INSERT INTO `sc` VALUES (4, 5);
INSERT INTO `sc` VALUES (4, 6);
INSERT INTO `sc` VALUES (4, 3);
INSERT INTO `sc` VALUES (4, 2);
INSERT INTO `sc` VALUES (4, 1);
INSERT INTO `sc` VALUES (4, 8);
INSERT INTO `sc` VALUES (6, 2);
INSERT INTO `sc` VALUES (6, 3);
INSERT INTO `sc` VALUES (6, 1);

-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`ID` int(22) NOT NULL,
`StuName` varchar(22) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`StuAge` int(22) NULL DEFAULT NULL,
`Password` varchar(22) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES (1, '张三', 66, '');
INSERT INTO `student` VALUES (2, '李四', 77, '');
INSERT INTO `student` VALUES (4, '王五', 25, '');
INSERT INTO `student` VALUES (6, '林冲', 33, '');
INSERT INTO `student` VALUES (7, '宋江', 44, '');
INSERT INTO `student` VALUES (8, '孙悟空', 99, '1343');

-- ----------------------------
-- Table structure for teacher
-- ----------------------------
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher` (
`Teaid` int(22) NOT NULL,
`Teaname` varchar(22) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`Teaposition` varchar(22) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`cid` int(22) NULL DEFAULT NULL,
PRIMARY KEY (`Teaid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`userAge` int(11) NULL DEFAULT NULL,
`userAddress` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 36 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES (14, 'wangwu', 66, 'shanghai');
INSERT INTO `user` VALUES (15, 'wangwu', 66, 'shanghai');
INSERT INTO `user` VALUES (19, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (20, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (21, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (22, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (23, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (24, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (25, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (26, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (27, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (28, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (29, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (30, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (31, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (32, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (33, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (34, 'wcd', 99, 'asfasf');
INSERT INTO `user` VALUES (35, 'wcd', 99, 'asfasf');

SET FOREIGN_KEY_CHECKS = 1;


 

 

 

 

 

 

 

 

 

posted @ 2019-05-28 19:47  崇州周柏豪  阅读(411)  评论(0编辑  收藏  举报