javaWeb课程设计(使用SSM框架)
- 程序简介
- 实现前的准备
- 系统设计
- 系统功能模块设计
- 系统流程设计
- 系统实现
- 程序架构
- 核心配置文件
- 登录实现
- 实现效果
- 总结
程序简介
这是本人的第一个博客,也是我自己的课程设计,是基于java Web技术的一个简单网站。本人曾经在学校某学生组织干过学生本部,这是根据当时自己管理的网站改版的。(大一时学的不是很好,现在才开始努力。新手,不喜勿喷,如果有大神想指点我也很欢迎,哈哈哈)
使用技术:
编程语言:java
框架:SSM
数据库:mysql
编译器:eclipse
开发环境:Windows
源码下载链接:
实现前的准备
程序实现前的准备:创建数据库、导入需要用到SSM架包。
1.数据库的创建
user1表
CREATE TABLE `user1` (
`id` char(12) NOT NULL,
`username` char(5) NOT NULL,
`password` char(12) NOT NULL,
`phone` int(11) DEFAULT NULL,
`post` char(12) DEFAULT '心理老师',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
user2表
CREATE TABLE `user2` (
`id` char(12) NOT NULL,
`username` char(5) NOT NULL,
`password` char(12) NOT NULL,
`phone` int(11) DEFAULT NULL,
`post` char(12) DEFAULT '学生会部长',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
user3表
CREATE TABLE `user3` (
`id` char(12) NOT NULL,
`username` char(5) NOT NULL,
`password` char(12) NOT NULL,
`phone` int(11) DEFAULT NULL,
`academy` char(12) DEFAULT NULL,
`classgrade` char(12) DEFAULT NULL,
`classteacher` char(12) DEFAULT NULL,
`post` char(12) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
record表(报送记录表)
CREATE TABLE `record` (
`number` int(11) NOT NULL AUTO_INCREMENT,
`academy` char(12) NOT NULL,
`classgrade` char(12) NOT NULL,
`classteacher` char(12) NOT NULL,
`rname` char(12) DEFAULT NULL,
`rphone` char(11) DEFAULT NULL,
`information` char(12) DEFAULT NULL,
`uname` char(12) NOT NULL,
PRIMARY KEY (`number`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8
2.导入架包
系统设计
系统功能模块设计
系统流程设计
内部执行流程1:
内部执行流程2:
系统实现
程序架构
核心配置文件
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>LkFeedbackSystem</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 配置加载Spring文件的监听器-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 编码过滤器 -->
<filter>
<filter-name>encoding</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>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置Spring MVC前端核心控制器 -->
<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:springmvc-config.xml</param-value>
</init-param>
<!-- 配置服务器启动后立即加载Spring MVC配置文件 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!--/:拦截所有请求(除了jsp)-->
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<!-- 读取db.properties -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<!--数据库驱动 -->
<property name="driverClassName" value="${jdbc.driver}" />
<!--连接数据库的url -->
<property name="url" value="${jdbc.url}" />
<!--连接数据库的用户名 -->
<property name="username" value="${jdbc.username}" />
<!--连接数据库的密码 -->
<property name="password" value="${jdbc.password}" />
<!--最大连接数 -->
<property name="maxTotal" value="${jdbc.maxTotal}" />
<!--最大空闲连接 -->
<property name="maxIdle" value="${jdbc.maxIdle}" />
<!--初始化连接数 -->
<property name="initialSize" value="${jdbc.initialSize}" />
</bean>
<!-- 事务管理器,依赖于数据源 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启事务注解 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 配置MyBatis工厂SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据源 -->
<property name="dataSource" ref="dataSource" />
<!--指定核MyBatis心配置文件位置 -->
<property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>
<!-- 配置mapper扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.gdupt.dao"/>
</bean>
<!-- 扫描Service -->
<context:component-scan base-package="com.gdupt.service" />
</beans>
db.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/lkfeedbacksystem?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=liukang
jdbc.maxTotal=30
jdbc.maxIdle=10
jdbc.initialSize=5
log4j.properties
# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.gdupt=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 别名定义 -->
<typeAliases>
<package name="com.gdupt.po" />
</typeAliases>
</configuration>
springmvc-config.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- 配置包扫描器,扫描@Controller注解的类 -->
<context:component-scan base-package="com.gdupt.controller" />
<!-- 加载注解驱动 -->
<mvc:annotation-driven> </mvc:annotation-driven>
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
登录实现
LoginController.java
package com.gdupt.controller;
import java.io.PrintWriter;
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.web.bind.annotation.RequestMapping;
import com.gdupt.po.User;
import com.gdupt.po.User1;
import com.gdupt.po.User2;
import com.gdupt.po.User3;
import com.gdupt.service.UserService;
@Controller
//@RequestMapping(value="/userLogin")
public class LoginController {
@Autowired
private UserService userService;
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
@RequestMapping(value="/login")
public String login(String id ,String password,String gender,HttpServletRequest req) {
String a="心委";
String b="学生会部长";
String c="心理老师";
//System.out.println(gender);
//System.out.println(gender.equals(a));
/*
User user=userService.checkUesr(id, password);
String d= user.getPost();//职位
req.getSession().setAttribute("user", user);
System.out.println(user);
if(user != null && gender.equals(d)) {
if(gender.equals(a)) {
return "user3/userMain3";
}else if(gender.equals(b)) {
return "user2/userMain2";
}else if(gender.equals(c)) {
return "user1/userMain1";
}else {
return "login";
}
}else {
return "login";
}
*/
if(gender.equals(a)) {//心委登录
User3 user3=userService.checkUesr3(id, password);
req.getSession().setAttribute("user3", user3);
if(user3 != null) {
return "user3/userMain3";
}else {
return "login";
}
}else if(gender.equals(b)) {//学生会登录
User2 user2=userService.checkUesr2(id, password);
req.getSession().setAttribute("user2", user2);
if(user2 != null) {
return "user2/userMain2";
}else {
return "login";
}
}else if(gender.equals(c)) {//教师登录
User1 user1=userService.checkUesr1(id, password);
req.getSession().setAttribute("user1", user1);
if(user1 != null) {
return "user1/userMain1";
}else {
return "login";
}
}else {
return "login";
}
}
}
login.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登录界面</title>
</head>
<body background="loginPhoto.jpg" >
<br><br>
<fieldset>
<center>
<br><br><br><br>
<h1 style="color:blue">Login</h1>
<br>
<form action="login" method="post">
<table>
<tr>
<td>账号:</td>
<td><input type="text" name="id"> </td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="radio" name="gender" value="心委" />心委</td>
<td><input type="radio" name="gender" value="学生会部长" />学生会
<input type="radio" name="gender" value="心理老师" />教师</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="登录" style="color:black">
</td>
</tr>
</table>
</form>
<br><br><br><br>
</center>
</fieldset>
</body>
</html>
实现效果
登录
修改信息
修改密码
①心委端个人主页
待上报
以上报
②学生会端
心委账户管理
③教师端
心委账户
学生会账户
所有记录
关注记录
学生关注统计
学院关注统计
总结
因为主要学的后台的程序开发,所以前端的界面做的是有点丑,而且程序也不是很完善,后期还会不断地学习改进、更新。