1 概述
本系统一共分为六大模块,每个模块对数据库的访问上是紧密相连的,各个模块访问的是同一个数据库,只是所访问的数据表不同而已。每个模块的功能都是按照在调研中搜集的资料进行编排制作的。依据上述功能的分析,系统在六大块的基础上每一大模块又分为几个模块:
(1) 密码修改:管理员登录系统后可以修改自己的密码信息。
(2) 管理员管理:管理员登录系统后可以管理、添加、删除、修改管理员信息,如账号、密码等。
(3) 教师人事管理:该模块主要分为教师信息添加、教师信息管理、教师信息查询、部门添加、部门管理,教师信息如编号、部门、姓名、年龄、工资卡号、入职年份等;部门信息如果名称、部门年限。
(4) 荣誉信息管理:管理员登录系统后可以管理荣誉信息、录入荣誉信息,如获得日期、老师、获奖名称、级别、参加人数、个人排名、本人得分等。
(5)工作内容信息:管理员登录系统后可以管理、查看工作内容信息,如开始日期、教师、工作信息名称 、工作小时数等。
(7) 教师登录信息:教师登录系统后可以管理我的信息,如修改密码等。
2 数据库表
表3 t_tea教师
字段名称 | 自动增长 | 字段类型 | 说明 |
id | - | int | - |
bianhao | - | varchar | 编号 |
name | - | varchar | 名称 |
sex | - | varchar | 性别 |
age | - | varchar | 年龄 |
tel | - | varchar | 电话 |
address | - | varchar | 地址 |
zhiwei | - | varchar | 职务 |
card | - | varchar | - |
ruzhinianfei | - | int | 任职年份 |
quanxian | - | int | 权限 |
loginName | - | varchar | 登录名称 |
loginPw | - | varchar | 密码 |
del | - | varchar | - |
bumen | - | varchar | 部门 |
3 关键代码
package com.action;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.DB;
import com.orm.Tea;
public class tea_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("teaAdd"))
{
teaAdd(req, res);
}
if(type.endsWith("teaMana"))
{
teaMana(req, res);
}
if(type.endsWith("teaDel"))
{
teaDel(req, res);
}
if(type.endsWith("teaEdit"))
{
teaEdit(req, res);
}
if(type.endsWith("teaSearch"))
{
teaSearch(req, res);
}
if(type.endsWith("teaSearch_bianhao"))
{
teaSearch_bianhao(req, res);
}
if(type.endsWith("teaQuanxian"))
{
teaQuanxian(req, res);
}
}
public void teaAdd(HttpServletRequest req,HttpServletResponse res)
{
String bianhao=req.getParameter("bianhao");
String name=req.getParameter("name");
String sex=req.getParameter("sex");
String age=req.getParameter("age");
String tel=req.getParameter("tel");
String address=req.getParameter("address");
String zhiwei=req.getParameter("zhiwei");
String card=req.getParameter("card");
String bumen=req.getParameter("bumen");
int ruzhinianfei=Integer.parseInt(req.getParameter("ruzhinianfei"));
String sql="insert into t_tea values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Object[] params={null,bianhao,name,sex,age,tel,address,zhiwei,card,ruzhinianfei,0,"","","no",bumen};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "tea?type=teaMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void teaEdit(HttpServletRequest req,HttpServletResponse res)
{
String bianhao=req.getParameter("bianhao");
String name=req.getParameter("name");
String sex=req.getParameter("sex");
String age=req.getParameter("age");
String tel=req.getParameter("tel");
String address=req.getParameter("address");
String zhiwei=req.getParameter("zhiwei");
String card=req.getParameter("card");
String bumen=req.getParameter("bumen");
int ruzhinianfei=Integer.parseInt(req.getParameter("ruzhinianfei"));
String sql="update t_tea set bumen='"+bumen+"', bianhao='"+bianhao+"',card='"+card+"',ruzhinianfei='"+ruzhinianfei+"', name='"+name+"',sex='"+sex+"',age='"+age+"',tel='"+tel+"',address='"+address+"',zhiwei='"+zhiwei+"' where id="+Integer.parseInt(req.getParameter("id"));
Object[] params={};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "tea?type=teaMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void teaDel(HttpServletRequest req,HttpServletResponse res)
{
int id=Integer.parseInt(req.getParameter("id"));
String sql="update t_tea set del=? where id=?";
Object[] params={"yes",id};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "tea?type=teaMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void teaMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String id=req.getParameter("teaId");
String page1=req.getParameter("page");
if(page1==null){
page1="1";
}
//分页设置
int EVERYPAGENUM=10;//每页条数
int page=Integer.parseInt(page1); //传递过来的当前页
int cou = 1;//得到信息总数
int pagecount=1; //总页数
String sql1="select count(*) as cou from t_tea where del='no'";
if(id!=null)sql1+=" and id="+id;
Object[] params1={};
DB mydb1=new DB();
try
{
mydb1.doPstm(sql1, params1);
ResultSet rs=mydb1.getRs();
while(rs.next())
{
cou= rs.getInt("cou");
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb1.closed();
if (cou % EVERYPAGENUM == 0) {
pagecount= cou / EVERYPAGENUM;
} else {
pagecount=cou / EVERYPAGENUM + 1;
}
req.setAttribute("EVERYPAGENUM", EVERYPAGENUM);
req.setAttribute("page", page);
req.setAttribute("cou", cou);
req.setAttribute("pagecount", pagecount);
List teaList=new ArrayList();
String sql="select * from t_tea where del='no'";
if(id!=null)sql+=" and id="+id;
sql1+=" order by bianhao desc";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
Tea tea=new Tea();
tea.setId(rs.getInt("id"));
tea.setBianhao(rs.getString("bianhao"));
tea.setName(rs.getString("name"));
tea.setSex(rs.getString("sex"));
tea.setAge(rs.getString("age"));
tea.setTel(rs.getString("tel"));
tea.setAddress(rs.getString("address"));
tea.setZhiwei(rs.getString("zhiwei"));
tea.setCard(rs.getString("card"));
tea.setRuzhinianfei(rs.getInt("ruzhinianfei"));
tea.setGongling(new Date().getYear()+1900-rs.getInt("ruzhinianfei"));
tea.setQuanxian(rs.getInt("quanxian"));
tea.setLoginName(rs.getString("loginName"));
tea.setLoginPw(rs.getString("loginPw"));
tea.setBumen(rs.getString("bumen"));
teaList.add(tea);
} else {
break; //减少空循环的时间
}
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("teaList", teaList);
req.getRequestDispatcher("admin/tea/teaMana.jsp").forward(req, res);
}
public void teaSearch(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String name=req.getParameter("name");
String page1=req.getParameter("page");
if(page1==null){
page1="1";
}
//分页设置
int EVERYPAGENUM=10;//每页条数
int page=Integer.parseInt(page1); //传递过来的当前页
int cou = 1;//得到信息总数
int pagecount=1; //总页数
String sql1="select count(*) as cou from t_tea where del='no' and name like '%"+name.trim()+"%'";
Object[] params1={};
DB mydb1=new DB();
try
{
mydb1.doPstm(sql1, params1);
ResultSet rs=mydb1.getRs();
while(rs.next())
{
cou= rs.getInt("cou");
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb1.closed();
if (cou % EVERYPAGENUM == 0) {
pagecount= cou / EVERYPAGENUM;
} else {
pagecount=cou / EVERYPAGENUM + 1;
}
req.setAttribute("EVERYPAGENUM", EVERYPAGENUM);
req.setAttribute("page", page);
req.setAttribute("cou", cou);
req.setAttribute("pagecount", pagecount);
List teaList=new ArrayList();
String sql="select * from t_tea where del='no' and name like '%"+name.trim()+"%'";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
Tea tea=new Tea();
tea.setId(rs.getInt("id"));
tea.setBianhao(rs.getString("bianhao"));
tea.setName(rs.getString("name"));
tea.setSex(rs.getString("sex"));
tea.setAge(rs.getString("age"));
tea.setTel(rs.getString("tel"));
tea.setAddress(rs.getString("address"));
tea.setZhiwei(rs.getString("zhiwei"));
tea.setRuzhinianfei(rs.getInt("ruzhinianfei"));
tea.setCard(rs.getString("card"));
tea.setGongling(new Date().getYear()+1900-rs.getInt("ruzhinianfei"));
tea.setQuanxian(rs.getInt("quanxian"));
tea.setLoginName(rs.getString("loginName"));
tea.setLoginPw(rs.getString("loginPw"));
tea.setBumen(rs.getString("bumen"));
teaList.add(tea);
} else {
break; //减少空循环的时间
}
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("teaList", teaList);
req.getRequestDispatcher("admin/tea/teaMana.jsp").forward(req, res);
}
public void teaSearch_bianhao(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String bianhao=req.getParameter("bianhao");
String page1=req.getParameter("page");
if(page1==null){
page1="1";
}
//分页设置
int EVERYPAGENUM=10;//每页条数
int page=Integer.parseInt(page1); //传递过来的当前页
int cou = 1;//得到信息总数
int pagecount=1; //总页数
String sql1="select count(*) as cou from t_tea where del='no' and bianhao like '%"+bianhao.trim()+"%'";
Object[] params1={};
DB mydb1=new DB();
try
{
mydb1.doPstm(sql1, params1);
ResultSet rs=mydb1.getRs();
while(rs.next())
{
cou= rs.getInt("cou");
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb1.closed();
if (cou % EVERYPAGENUM == 0) {
pagecount= cou / EVERYPAGENUM;
} else {
pagecount=cou / EVERYPAGENUM + 1;
}
req.setAttribute("EVERYPAGENUM", EVERYPAGENUM);
req.setAttribute("page", page);
req.setAttribute("cou", cou);
req.setAttribute("pagecount", pagecount);
List teaList=new ArrayList();
String sql="select * from t_tea where del='no' and bianhao like '%"+bianhao.trim()+"%'";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
Tea tea=new Tea();
tea.setId(rs.getInt("id"));
tea.setBianhao(rs.getString("bianhao"));
tea.setName(rs.getString("name"));
tea.setSex(rs.getString("sex"));
tea.setAge(rs.getString("age"));
tea.setTel(rs.getString("tel"));
tea.setAddress(rs.getString("address"));
tea.setZhiwei(rs.getString("zhiwei"));
tea.setRuzhinianfei(rs.getInt("ruzhinianfei"));
tea.setCard(rs.getString("card"));
tea.setGongling(new Date().getYear()+1900-rs.getInt("ruzhinianfei"));
tea.setQuanxian(rs.getInt("quanxian"));
tea.setLoginName(rs.getString("loginName"));
tea.setLoginPw(rs.getString("loginPw"));
teaList.add(tea);
} else {
break; //减少空循环的时间
}
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("teaList", teaList);
req.getRequestDispatcher("admin/tea/teaMana.jsp").forward(req, res);
}
public void teaQuanxian(HttpServletRequest req,HttpServletResponse res)
{
int id=Integer.parseInt(req.getParameter("id"));
int quanxian=Integer.parseInt(req.getParameter("quanxian"));
String loginName=req.getParameter("loginName");
String loginPw=req.getParameter("loginPw");
String sql="update t_tea set quanxian=?,loginName=?,loginPw=? where id="+id;
Object[] params={quanxian,loginName,loginPw};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "tea?type=teaMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
{
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try
{
dispatch.forward(request, response);
return;
}
catch (ServletException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void destroy()
{
}
}
4 效果演示
idea或eclipse开发,mysql数据库