作者主页:源码空间站2022
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目包含三种角色:运动员、裁判员、管理员;
运动员角色包含以下功能:
运动员登录,个人信息修改,运动成绩查询,比赛项目查询等功能。
裁判员角色包含以下功能:
登录界面,查看运动员,运动成绩查看,录入运动成绩,比赛项目查询等功能。
管理员角色包含以下功能:
登录页面,管理员首页,运动员管理,裁判员管理,运动成绩查询,比赛类型管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:否;
技术栈
JSP+Servlet+JavaBean+MySQL+css+javascript
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中src/util/DB.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/jspyundonghuimanager/ 登录
注:tomcat中配置项目路径必须为jspyundonghuimanager,否则会有异常
管理员账号/密码:admin/admin
学生运动员角色账号/密码:student/123456
裁判老师角色账号/密码:teacher/123456
运行截图
管理员角色
裁判员角色
运动员角色
相关代码
Cla2SubImpl
package impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import util.DB;
import dao.ICla2Sub;
import entity.Cla2Sub;
public class Cla2SubImpl implements ICla2Sub {
private Connection conn;
private PreparedStatement pst;
private ResultSet rs;
public int add(Cla2Sub cla2Sub) {
int i = 0;
try {
conn = DB.getConn();
pst = conn
.prepareStatement("INSERT INTO cla2sub (cla_id,sub_id,tec_id) VALUES (?,?,?)");
pst.setInt(1, cla2Sub.getClasses().getId());
pst.setInt(2, cla2Sub.getSubject().getId());
pst.setInt(3, cla2Sub.getTeacher().getId());
i = pst.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
DB.close(conn, pst, rs);
}
return i;
}
public void delete(Cla2Sub cla2Sub) {
try {
conn = DB.getConn();
pst = conn
.prepareStatement("DELETE FROM cla2sub WHERE cla2sub_id = ?");
pst.setInt(1, cla2Sub.getId());
pst.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
DB.close(conn, pst, rs);
}
}
public void update(Cla2Sub cla2Sub) {
try {
conn = DB.getConn();
pst = conn
.prepareStatement("UPDATE cla2sub SET cla_id = ?, sub_id = ?,tec_id = ? WHERE cla2sub_id = ?");
pst.setInt(1, cla2Sub.getClasses().getId());
pst.setInt(2, cla2Sub.getSubject().getId());
pst.setInt(3, cla2Sub.getTeacher().getId());
pst.setInt(4, cla2Sub.getId());
pst.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
DB.close(conn, pst, rs);
}
}
public Cla2Sub findCla2sub(int cla_id, int tec_id, int sub_id) {
Cla2Sub cla2sub = new Cla2Sub();
try {
conn = DB.getConn();
pst = conn
.prepareStatement("SELECT * FROM cla2sub WHERE sub_id = ? AND cla_id = ? AND tec_id = ? order by cla2sub_id");
pst.setInt(1, sub_id);
pst.setInt(2, cla_id);
pst.setInt(3, tec_id);
rs = pst.executeQuery();
if (rs.next()) {
cla2sub.setId(rs.getInt(1));
cla2sub.setClasses(new ClassesImpl().query("cla_id",
rs.getString(2)).get(0));
cla2sub.setSubject(new SubjectImpl().query("sub_id",
rs.getString(3)).get(0));
}
} catch (SQLException e) {
e.printStackTrace();
}
return cla2sub;
}
public List<Cla2Sub> query(String type, String value) {
List<Cla2Sub> list = new ArrayList<Cla2Sub>();
try {
conn = DB.getConn();
if (type.equals("cla2sub_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub where cla2sub_id = ? order by cla2sub_id");
pst.setString(1, value);
} else if (type.equals("stu_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub WHERE cla_id IN(SELECT cla_id FROM student WHERE stu_id = ?) order by cla2sub_id");
pst.setString(1, value);
} else if (type.equals("cla_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub where cla_id = ? order by cla2sub_id");
pst.setString(1, value);
} else if (type.equals("sub_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub where sub_id = ? order by cla2sub_id");
pst.setString(1, value);
} else if (type.equals("tec_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub where tec_id = ? order by cla2sub_id");
pst.setString(1, value);
} else if (type.equals("sub_name")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub WHERE sub_id IN(SELECT sub_id FROM `subject` WHERE sub_name LIKE ?) order by cla2sub_id");
pst.setString(1, "%" + value + "%");
} else if (type.equals("cla_name")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub WHERE cla_id IN(SELECT cla_id FROM classes WHERE cla_name LIKE ?) order by cla2sub_id");
pst.setString(1, "%" + value + "%");
} else {
pst = conn
.prepareStatement("SELECT * FROM cla2sub order by cla2sub_id");
}
rs = pst.executeQuery();
while (rs.next()) {
Cla2Sub cla2Sub = new Cla2Sub();
cla2Sub.setId(rs.getInt(1));
cla2Sub.setClasses(new ClassesImpl().query("cla_id",
rs.getString(2)).get(0));
cla2Sub.setSubject(new SubjectImpl().query("sub_id",
rs.getString(3)).get(0));
cla2Sub.setTeacher(new TeacherImpl().query("tec_id",
rs.getString(4)).get(0));
list.add(cla2Sub);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DB.close(conn, pst, rs);
}
return list;
}
public List<Cla2Sub> query(String type, String value, int currentPage) {
currentPage = (currentPage - 1) * 10;
List<Cla2Sub> list = new ArrayList<Cla2Sub>();
try {
conn = DB.getConn();
if (type.equals("cla2sub_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub where cla2sub_id = ? order by cla2sub_id limit ?,10");
pst.setString(1, value);
pst.setInt(2, currentPage);
} else if (type.equals("stu_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub WHERE cla_id IN(SELECT cla_id FROM student WHERE stu_id = ?) order by cla2sub_id limit ?,10");
pst.setString(1, value);
pst.setInt(2, currentPage);
}
else if (type.equals("cla_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub where cla_id = ? order by cla2sub_id limit ?,10");
pst.setString(1, value);
pst.setInt(2, currentPage);
} else if (type.equals("sub_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub where sub_id = ? order by cla2sub_id limit ?,10");
pst.setString(1, value);
pst.setInt(2, currentPage);
} else if (type.equals("tec_id")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub where tec_id = ? order by cla2sub_id limit ?,10");
pst.setString(1, value);
pst.setInt(2, currentPage);
} else if (type.equals("sub_name")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub WHERE sub_id IN(SELECT sub_id FROM `subject` WHERE sub_name LIKE ?) order by cla2sub_id limit ?,10");
pst.setString(1, "%" + value + "%");
pst.setInt(2, currentPage);
} else if (type.equals("cla_name")) {
pst = conn
.prepareStatement("SELECT * FROM cla2sub WHERE cla_id IN(SELECT cla_id FROM classes WHERE cla_name LIKE ?) order by cla2sub_id limit ?,10");
pst.setString(1, "%" + value + "%");
pst.setInt(2, currentPage);
} else {
pst = conn
.prepareStatement("SELECT * FROM cla2sub order by cla2sub_id limit ?,10");
pst.setInt(1, currentPage);
}
rs = pst.executeQuery();
while (rs.next()) {
Cla2Sub cla2Sub = new Cla2Sub();
cla2Sub.setId(rs.getInt(1));
cla2Sub.setClasses(new ClassesImpl().query("cla_id",
rs.getString(2)).get(0));
cla2Sub.setSubject(new SubjectImpl().query("sub_id",
rs.getString(3)).get(0));
cla2Sub.setTeacher(new TeacherImpl().query("tec_id",
rs.getString(4)).get(0));
list.add(cla2Sub);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DB.close(conn, pst, rs);
}
return list;
}
public int getCountPage(String type, String value) {
int countPages = 0;
try {
conn = DB.getConn();
if (type.equals("cla2sub_id")) {
pst = conn
.prepareStatement("SELECT COUNT(*) FROM cla2sub where cla2sub_id = ?");
pst.setString(1, value);
} else if (type.equals("stu_id")) {
pst = conn
.prepareStatement("SELECT COUNT(*) FROM cla2sub WHERE cla_id IN(SELECT cla_id FROM student WHERE stu_id = ?) order by cla2sub_id");
pst.setString(1, value);
} else if (type.equals("cla_id")) {
pst = conn
.prepareStatement("SELECT COUNT(*) FROM cla2sub where cla_id = ?");
pst.setString(1, value);
} else if (type.equals("sub_id")) {
pst = conn
.prepareStatement("SELECT COUNT(*) FROM cla2sub where sub_id = ?");
pst.setString(1, value);
} else if (type.equals("tec_id")) {
pst = conn
.prepareStatement("SELECT COUNT(*) FROM cla2sub where tec_id = ?");
pst.setString(1, value);
} else if (type.equals("sub_name")) {
pst = conn
.prepareStatement("SELECT COUNT(*) FROM cla2sub WHERE sub_id IN(SELECT sub_id FROM `subject` WHERE sub_name LIKE ?)");
pst.setString(1, "%" + value + "%");
} else if (type.equals("cla_name")) {
pst = conn
.prepareStatement("SELECT COUNT(*) FROM cla2sub WHERE cla_id IN(SELECT cla_id FROM classes WHERE cla_name LIKE ?)");
pst.setString(1, "%" + value + "%");
} else {
pst = conn.prepareStatement("SELECT COUNT(*) FROM cla2sub");
}
rs = pst.executeQuery();
while (rs.next()) {
countPages = rs.getInt(1);
countPages = countPages % 10 == 0 ? countPages / 10
: countPages / 10 + 1;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DB.close(conn, pst, rs);
}
return countPages;
}
}
ClassesImpl
package impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import util.DB;
import dao.IClasses;
import entity.Classes;
public class ClassesImpl implements IClasses
{
private Connection conn;
private PreparedStatement pst;
private ResultSet rs;
public Classes add(Classes classes)
{
try
{
conn = DB.getConn();
pst = conn.prepareStatement("INSERT INTO classes (cla_name,maj_id,cla_tec) VALUES (?,?,?)", Statement.RETURN_GENERATED_KEYS);
pst.setString(1, classes.getName());
pst.setInt(2, classes.getMajor().getId());
pst.setString(3, classes.getTecName());
pst.executeUpdate();
rs = pst.getGeneratedKeys();
if (rs.next())
{
classes = query("cla_id", rs.getString(1)).get(0);
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DB.close(conn, pst, rs);
}
return classes;
}
public void delete(Classes classes)
{
try
{
conn = DB.getConn();
pst = conn.prepareStatement("DELETE FROM classes WHERE cla_id = ?");
pst.setInt(1, classes.getId());
pst.executeUpdate();
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DB.close(conn, pst, rs);
}
}
public void update(Classes classes)
{
try
{
conn = DB.getConn();
pst = conn.prepareStatement("UPDATE classes SET cla_name = ?,maj_id = ?,cla_tec= ? WHERE cla_id = ?");
pst.setString(1, classes.getName());
pst.setInt(2, classes.getMajor().getId());
pst.setString(3, classes.getTecName());
pst.setInt(4, classes.getId());
pst.executeUpdate();
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DB.close(conn, pst, rs);
}
}
public List<Classes> query(String type, String value)
{
ArrayList<Classes> list = new ArrayList<Classes>();
try
{
conn = DB.getConn();
if (type.equals("cla_id"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE cla_id = ? order by cla_id");
pst.setString(1, value);
} else if (type.equals("cla_name"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE cla_name like ? order by cla_id");
pst.setString(1, "%" + value + "%");
} else if (type.equals("maj_id"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE maj_id = ? order by cla_id");
pst.setString(1, value);
} else if (type.equals("maj_name"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE maj_id IN(SELECT maj_id FROM major WHERE maj_name LIKE ?) order by cla_id");
pst.setString(1, "%" + value + "%");
}else if (type.equals("cla_tec"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE cla_tec LIKE ? order by cla_id");
pst.setString(1, "%" + value + "%");
}
else
{
pst = conn.prepareStatement("SELECT * FROM classes order by cla_id");
}
rs = pst.executeQuery();
while (rs.next())
{
Classes classes = new Classes();
classes.setId(rs.getInt(1));
classes.setName(rs.getString(2));
classes.setMajor(new MajorImpl().query("maj_id", rs.getString(3)).get(0));
classes.setTecName(rs.getString(4));
list.add(classes);
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DB.close(conn, pst, rs);
}
return list;
}
public List<Classes> query(String type, String value, int currentPage)
{
currentPage = (currentPage - 1) * 10;
ArrayList<Classes> list = new ArrayList<Classes>();
try
{
conn = DB.getConn();
if (type.equals("cla_id"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE cla_id = ? order by cla_id limit ?,10");
pst.setString(1, value);
pst.setInt(2, currentPage);
} else if (type.equals("cla_name"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE cla_name like ? order by cla_id limit ?,10");
pst.setString(1, "%" + value + "%");
pst.setInt(2, currentPage);
} else if (type.equals("maj_id"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE maj_id = ? order by cla_id limit ?,10");
pst.setString(1, value);
pst.setInt(2, currentPage);
} else if (type.equals("maj_name"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE maj_id IN(SELECT maj_id FROM major WHERE maj_name LIKE ?) order by cla_id limit ?,10");
pst.setString(1, "%" + value + "%");
pst.setInt(2, currentPage);
} else if (type.equals("cla_tec"))
{
pst = conn.prepareStatement("SELECT * FROM classes WHERE cla_tec = ? order by cla_id limit ?,10");
pst.setString(1, value);
pst.setInt(2, currentPage);
}else
{
pst = conn.prepareStatement("SELECT * FROM classes order by cla_id limit ?,10");
pst.setInt(1, currentPage);
}
rs = pst.executeQuery();
while (rs.next())
{
Classes classes = new Classes();
classes.setId(rs.getInt(1));
classes.setName(rs.getString(2));
classes.setMajor(new MajorImpl().query("maj_id", rs.getString(3)).get(0));
classes.setTecName(rs.getString(4));
list.add(classes);
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DB.close(conn, pst, rs);
}
return list;
}
public int getCountPage(String type, String value)
{
int countPages = 0;
try
{
conn = DB.getConn();
if (type.equals("cla_id"))
{
pst = conn.prepareStatement("SELECT COUNT(*) FROM classes WHERE cla_id = ?");
pst.setString(1, value);
} else if (type.equals("cla_name"))
{
pst = conn.prepareStatement("SELECT COUNT(*) FROM classes WHERE cla_name like ?");
pst.setString(1, "%" + value + "%");
} else if (type.equals("maj_id"))
{
pst = conn.prepareStatement("SELECT COUNT(*) FROM classes WHERE maj_id = ?");
pst.setString(1, value);
} else if (type.equals("maj_name"))
{
pst = conn.prepareStatement("SELECT COUNT(*) FROM classes WHERE maj_id IN(SELECT maj_id FROM major WHERE maj_name LIKE ?)");
pst.setString(1, "%" + value + "%");
} else if (type.equals("cla_tec"))
{
pst = conn.prepareStatement("SELECT COUNT(*) FROM classes WHERE cla_tec = ?");
pst.setString(1, value);
} else
{
pst = conn.prepareStatement("SELECT COUNT(*) FROM classes");
}
rs = pst.executeQuery();
while (rs.next())
{
countPages = rs.getInt(1);
countPages = countPages % 10 == 0 ? countPages / 10 : countPages / 10 + 1;
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DB.close(conn, pst, rs);
}
return countPages;
}
}
如果也想学习本系统,下面领取。关注并回复:036jsp