1 项目简介
1.1项目意义
学校学生管理是教务管理中的一个极为重要的环节,它是整个管理的核心和基础。在此,基于SpringMVC模式编写了学生学籍管理网站。
1.2项目说明
该项目主要开发针对学校学生学籍信息的一套简单管理系统。实现的功能主要有:管理员的登录及相关信息的修改。进入学籍管理系统有学生基本信息与班级信息两个子页面查看,可以进行增删查改等操作。页面的布局使用了easyui模板。
1.3关键技术
SpringMVC
JDBC的连接(MySql)
JDBC增删查改的实现
常见数据结构的Java实现
HTML5
JavaScript
Servlet
2 总体设计
2.1数据表分析总E-R图
3 详细设计与实现
3.1数据库建表
3.2设计实体类
学生类与Depart类
package smserves;
//实体类,封装Depart类数据/*** @triumph*/
public class Grade {
private int id;
private String depart;
private String gradename;
private String gradeDesc;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDepart() {
return depart;
}
public void setDepart(String depart) {
this.depart = depart;
}
public String getGradename() {
return gradename;
}
public void setGradename(String gradename) {
this.gradename = gradename;
}
public String getGradeDesc() {
return gradeDesc;
}
public void setGradeDesc(String gradeDesc) {
this.gradeDesc = gradeDesc;
}
public Grade(int id, String depart, String gradename, String gradeDesc) {
this.id = id;
this.depart = depart;
this.gradename = gradename;
this.gradeDesc = gradeDesc;
}
public Grade(String depart, String gradename, String gradeDesc) {
this.depart = depart;
this.gradename = gradename;
this.gradeDesc = gradeDesc;
}
public Grade() {
}
public Grade(int id) {
this.id = id;
}
}
3.3封装DBUtil类,用于连接到MySQL数据库
package smentiy;
//工具类/*** @triumph*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class smentiy {
private String smUrl= "jdbc:mysql://127.0.0.1:3306/mydb";
private String smName="root";
private String smPwd="1996";
private String smDriver="com.mysql.jdbc.Driver";
public Connection getConnection() throws Exception {
Class.forName(smDriver);
return DriverManager.getConnection(smUrl,smName,smPwd);
}
//可利用Spring工厂模式将数据封装于applicationContext.xml配置文件中,便于解耦合。
3.4创建学生信息管理对象(Dao)
package smdao;
4
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import smentiy.PageBean;
import smentiy.StringVDate;
import smentiy.smentiy1;
import smserves.Score;
public class Scoredao {
//搜索信息public ResultSet scoreList(Connection con,PageBean page,Score score,String b_bir,String e_bir) throws Exception {
StringBuffer sb = new StringBuffer("select * from stu_score ");//StringBuffer可以拼接语句//if(!smentiy1.isEmpty(score.getStuNo())||!smentiy1.isEmpty(score.getStuName())||!smentiy1.isEmpty(score.getJava())||!smentiy1.isEmpty(b_bir)||!smentiy1.isEmpty(e_bir)) {//sb.append(" where stuNo like '%"+score.getStuNo()+ "%' and stuName like '%"+score.getStuName()+ "%' and Java like '%"+score.getJava()+ "%' and birthday >='"+b_bir+"' and birthday <='"+e_bir+"' ");//}if(smentiy1.isEmpty(e_bir)) {
if(!smentiy1.isEmpty(score.getStuNo())||!smentiy1.isEmpty(score.getStuName())||!smentiy1.isEmpty(score.getJava())||!smentiy1.isEmpty(b_bir)) {
sb.append(" where stuNo like '%"+score.getStuNo()+ "%' and stuName like '%"+score.getStuName()+ "%' and Java like '%"+score.getJava()+ "%' and birthday >='"+b_bir+"' ");
}
}else if(smentiy1.isEmpty(b_bir)) {
if(!smentiy1.isEmpty(score.getStuNo())||!smentiy1.isEmpty(score.getStuName())||!smentiy1.isEmpty(score.getJava())||!smentiy1.isEmpty(e_bir)) {
sb.append(" where stuNo like '%"+score.getStuNo()+ "%' and stuName like '%"+score.getStuName()+ "%' and Java like '%"+score.getJava()+ "%' and birthday <='"+e_bir+"' ");
}
}else {
sb.append(" where stuNo like '%"+score.getStuNo()+ "%' and stuName like '%"+score.getStuName()+ "%' and Java like '%"+score.getJava()+ "%' and birthday >='"+b_bir+"' and birthday <='"+e_bir+"' ");
}
if(page!=null) {
sb.append(" limit "+page.getStart()+","+page.getPagenum());//记得拼接前和后 要有一个空格 拼接限制从0开始 总共10页语句}
PreparedStatement ps = con.prepareStatement(sb.toString());
return ps.executeQuery();
}
//删除信息public int scoreDelete(Connection con,String ids) throws Exception{
String sql="delete from stu_score where stuid in("+ids+")";
PreparedStatement ps = con.prepareStatement(sql);
return ps.executeUpdate();
}
//添加信息public int scoreAdd(Connection con,Score score) throws Exception{
String sql = "insert into stu_score(stuNo,stuName,sex,Java,birthday,stuDesc) values(?,?,?,?,?,?)";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, score.getStuNo());
ps.setString(2, score.getStuName());
ps.setString(3, score.getSex());
ps.setString(4, score.getJava());
ps.setString(5,StringVDate.ToString(score.getBirthday()));
ps.setString(6, score.getStuDesc());
return ps.executeUpdate();
}
//修改信息public int scoreModify(Connection con,Score score) throws Exception{
String sql = "update stu_score set stuNo=?,stuName=?,sex=?,Java=?,birthday=?,stuDesc=? where stuid = ?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, score.getStuNo());
ps.setString(2, score.getStuName());
ps.setString(3, score.getSex());
ps.setString(4, score.getJava());
ps.setString(5,StringVDate.ToString(score.getBirthday()));
ps.setString(6, score.getStuDesc());
ps.setInt(7, score.getStuid());
return ps.executeUpdate();
}
}
3.5页面编写
#box{
width:400px;
height:300px;
margin:100px auto;
background-color:rgba(0,0,0,0);
}
#ipt1{
border:1px solid gray;
width:300px;
height:30px;
background-color:rgba(0,0,0,0);
}
#box_ipt1{
width:300px;
height:30px;
margin:0 auto;
margin-top:50px;
}
#ipt2{
border:1px solid gray;
width:300px;
height:30px;
background-color:rgba(0,0,0,0);
}
#box_ipt2{
width:300px;
height:30px;
margin:0 auto;
margin-top:30px;
}
#ipt3{
border:1px solid gray;
width:300px;
height:40px;
background-color:rgba(0,0,0,0);
}
#box_ipt3{
width:300px;
height:30px;
margin:0 auto;
margin-top:30px;
}
#box_error{
width:300px;
height:30px;
margin:0 auto;
margin-top:30px;
text-align:center;
}
这是凯旋的网站!
${error}