作者主页:夜未央5788
简介: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项目:否;
技术栈
1. 后端:mysql+Spring+hibernate+spring mcv
2. 前端:JSP+CSS+JavaScript+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
管理员账号/密码:admin/111111
学生账号/密码:101/111111
教师账号/密码:js12/111111
运行截图
管理员角色
教师角色界面
学生角色界面
相关代码
教室管理控制器
@Controller("classRoomAction")
@Scope("prototype")
public class ClassRoomAction extends BaseAction implements ModelDriven<ClassRoom>{
private static final long serialVersionUID = 1L;
//==========model==============
private ClassRoom classRoom;
@Override
public ClassRoom getModel() {
if(classRoom==null) classRoom = new ClassRoom();
return classRoom;
}
//==========model==============
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private ClassRoomService classRoomService;
@Autowired
private TeacherClassService teacherClassService;
//依赖注入 end dao/service/===
//-------------------------华丽分割线---------------------------------------------
//============自定义参数start=============
//============自定义参数end=============
//-------------------------华丽分割线---------------------------------------------
//============文件上传start=======================================================
private File file;
//提交过来的file的名字
private String fileFileName;
//提交过来的file的MIME类型
private String fileContentType;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
//============文件上传end=========================================================
public String jsonAction() {
// dataMap中的数据将会被Struts2转换成JSON字符串,所以这里要先清空其中的数据
jsonMap.clear();
jsonMap.put("success", true);
return JSON_TYPE;
}
//-------------------------华丽分割线---------------------------------------------//
//=============公=======共=======方=======法==========区=========start============//
/**
* 列表分页查询
*/
public String classRoom(){
Map<String,Object> alias = new HashMap<String,Object>();
StringBuffer sb = new StringBuffer();
sb = sb.append("from ClassRoom where 1=1 and isDelete = 0 ");
if(classRoom!=null && classRoom.getName() !=null && !"".equals(classRoom.getName())){
sb.append(" and name like :realName ");
alias.put("realName", "%" +classRoom.getName()+ "%" );
}
sb = sb.append("order by id desc");
Pager<ClassRoom> pagers = classRoomService.findByAlias(sb.toString(),alias);
ActionContext.getContext().put("pagers", pagers);
ActionContext.getContext().put("Obj", classRoom);
return SUCCESS;
}
public String xkRoom(){
Map<String,Object> alias = new HashMap<String,Object>();
StringBuffer sb = new StringBuffer();
sb = sb.append("from ClassRoom where 1=1 and isDelete = 0 ");
if(classRoom!=null && classRoom.getName() !=null && !"".equals(classRoom.getName())){
sb.append(" and name like :realName ");
alias.put("realName", "%" +classRoom.getName()+ "%" );
}
sb = sb.append("order by id desc");
Pager<ClassRoom> pagers = classRoomService.findByAlias(sb.toString(),alias);
ActionContext.getContext().put("pagers", pagers);
ActionContext.getContext().put("Obj", classRoom);
return SUCCESS;
}
public String xkRoom2(){
Map<String,Object> alias = new HashMap<String,Object>();
StringBuffer sb = new StringBuffer();
sb = sb.append("from ClassRoom where 1=1 and isDelete = 0 ");
if(classRoom!=null && classRoom.getName() !=null && !"".equals(classRoom.getName())){
sb.append(" and name like :realName ");
alias.put("realName", "%" +classRoom.getName()+ "%" );
}
sb = sb.append("order by id desc");
Pager<ClassRoom> pagers = classRoomService.findByAlias(sb.toString(),alias);
ActionContext.getContext().put("pagers", pagers);
ActionContext.getContext().put("Obj", classRoom);
return SUCCESS;
}
public String cjRoom(){
List<ClassRoom>list = new ArrayList<ClassRoom>();
Integer loginId = UserUtils.getLoginId();
List<TeacherClass> checkList = teacherClassService.listByAlias("from TeacherClass where teacher.id="+loginId, null);
if(!isEmpty(checkList)){
for (TeacherClass t :checkList) {
list.add(t.getClassroom());
}
}
ActionContext.getContext().put("pagers", list);
ActionContext.getContext().put("Obj", classRoom);
return SUCCESS;
}
/**
* 跳转到添加页面
* @return
*/
public String add(){
return SUCCESS;
}
/**
* 执行添加
* @return
*/
public String exAdd(){
classRoom.setIsDelete(0);
classRoomService.save(classRoom);
ActionContext.getContext().put("url", "/classRoom_classRoom.do");
return "redirect";
}
/**
* 查看详情页面
* @return
*/
public String view(){
ClassRoom n = classRoomService.getById(classRoom.getId());
ActionContext.getContext().put("Obj", n);
return SUCCESS;
}
/**
* 跳转修改页面
* @return
*/
public String update(){
ClassRoom n = classRoomService.getById(classRoom.getId());
ActionContext.getContext().put("Obj", n);
return SUCCESS;
}
/**
* 执行修改
* @return
*/
public String exUpdate(){
ClassRoom n = classRoomService.getById(classRoom.getId());
n.setName(classRoom.getName());
n.setNj(classRoom.getNj());
classRoomService.update(n);
ActionContext.getContext().put("url", "/classRoom_classRoom.do");
return "redirect";
}
/**
* 删除
* @return
*/
public String delete(){
ClassRoom n = classRoomService.getById(classRoom.getId());
n.setIsDelete(1);
classRoomService.update(n);
ActionContext.getContext().put("url", "/classRoom_classRoom.do");
return "redirect";
}
//=============公=======共=======方=======法==========区=========end============//
//-------------------------华丽分割线---------------------------------------------//
//=============自=======定=======义=========方=======法==========区=========start============//
//=============自=======定=======义=========方=======法==========区=========end============//
}
登录管理控制器
@Controller("loginAction")
@Scope("prototype")
public class LoginAction extends BaseAction {
//============依赖注入start================
@Autowired
private ManageService manageService;//管理
@Autowired
private UserService userService;//用户
@Autowired
private NewsService newsService;
@Autowired
private TeacherService teacherService;
//===========依赖注入end==================
//-------------------------华丽分割线---------------------------------------------
//============自定义参数start=============
private Integer role;
private String newPass;
public String getNewPass() {
return newPass;
}
public void setNewPass(String newPass) {
this.newPass = newPass;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
private String name;
private String pass;
private String phone;
private String userName;//用户名
private String passWord;//密码
private String realName;
//============自定义参数end=============
//-------------------------华丽分割线---------------------------------------------
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
//============文件上传start=============
private File file;
//提交过来的file的名字
private String fileFileName;
//提交过来的file的MIME类型
private String fileContentType;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
//============文件上传end=============
//-------------------------华丽分割线---------------------------------------------
public String main(){
return "success";
}
public String left(){
return "success";
}
public String open(){
return "success";
}
public String login() {
return "login";
}
//用户登陆
public String ulogin() {
return "success";
}
/**
* 用户首页
* @return
*/
public String uIndex() {
return JSON_TYPE;
}
public String home() {
return "success";
}
//注册
public String res() throws UnsupportedEncodingException{
User user = new User();
if(!isEmpty(realName)){
String str = URLDecoder.decode((new String(realName.getBytes("ISO8859-1"), "UTF-8")), "UTF-8");
user.setRealName(str);
}
user.setCreateTime(new Date());
user.setPassWord(pass);
user.setPhone(phone);
user.setIsDelete(0);
user.setUserName(name);
Integer id = userService.save2(user);
return "json";
}
//用户登陆
public String utlogin(){
String hql = "from User where userName = :userName and passWord = :passWord";
Map<String,Object> alias = new HashMap<String,Object>();
alias.put("userName",name);
alias.put("passWord", pass);
List<User> manageList=userService.getByHQL(hql, alias);
if(manageList.size()>0){
//将用户信息放入session
HttpSession session = ServletActionContext.getRequest()
.getSession();
session.setAttribute("userName", manageList.get(0).getRealName());
session.setAttribute("userId",manageList.get(0).getId() );
session.setAttribute("manage", manageList.get(0));
session.setAttribute("roleId", role);
jsonMap.put("result", 1);
jsonMap.put("userId", manageList.get(0).getId() );
return "json";
}else{
jsonMap.put("result", 2);
return "json";
}
}
//登录
public String toLogin(){
/*<option value ="1">管理员</option>
<option value="2">教师</option>
<option value="3">学生</option>*/
if(role == 1){
String hql = "from Manage where name = :userName and passWord = :passWord";
Map<String,Object> alias = new HashMap<String,Object>();
alias.put("userName",userName);
alias.put("passWord", passWord);
List<Manage> manageList=manageService.getByHQL(hql, alias);
if(manageList.size()>0){
//将用户信息放入session
HttpSession session = ServletActionContext.getRequest()
.getSession();
session.setAttribute("role", manageList.get(0).getType());
session.setAttribute("userName", manageList.get(0).getRealName());
session.setAttribute("userId",manageList.get(0).getId() );
session.setAttribute("manage", manageList.get(0));
session.setAttribute("roleId", role);
jsonMap.put("res", 1);
}else{
jsonMap.put("res", 2);
}
}
if(role == 2){
String hql = "from Teacher where userName = :userName and passWrd = :passWord";
Map<String,Object> alias = new HashMap<String,Object>();
alias.put("userName",userName);
alias.put("passWord", passWord);
List<Teacher> manageList=teacherService.getByHQL(hql, alias);
if(manageList.size()>0){
//将用户信息放入session
HttpSession session = ServletActionContext.getRequest()
.getSession();
session.setAttribute("role", 2);
session.setAttribute("userName", manageList.get(0).getRealName());
session.setAttribute("userId",manageList.get(0).getId() );
session.setAttribute("manage", manageList.get(0));
session.setAttribute("roleId", role);
jsonMap.put("res", 1);
}else{
jsonMap.put("res", 2);
}
}
if(role == 3){
String hql = "from User where userName = :userName and passWord = :passWord";
Map<String,Object> alias = new HashMap<String,Object>();
alias.put("userName",userName);
alias.put("passWord", passWord);
List<User> manageList=userService.getByHQL(hql, alias);
if(manageList.size()>0){
//将用户信息放入session
HttpSession session = ServletActionContext.getRequest()
.getSession();
session.setAttribute("role", 3);
session.setAttribute("userName", manageList.get(0).getRealName());
session.setAttribute("userId",manageList.get(0).getId() );
session.setAttribute("manage", manageList.get(0));
session.setAttribute("roleId", role);
jsonMap.put("res", 1);
}else{
jsonMap.put("res", 2);
}
}
return "json";
}
//退出
public String tuichu() {
ActionContext ac = ActionContext.getContext();
Map session = ac.getSession();
session.remove("userName");
session.remove("userId");
return "login";
}
public String toXiugai(){
return SUCCESS;
}
public String xiugai(){
Integer loginId = UserUtils.getLoginId();
User byId = userService.getById(loginId);
if(byId.getPassWord().equals(passWord)){
byId.setPassWord(newPass);
userService.update(byId);
jsonMap.put("res", 1);
}else{
jsonMap.put("res", 2);
jsonMap.put("mess", "原始密码输入错误");
}
return "json";
}
}
教师管理控制器
@Controller("teacherAction")
@Scope("prototype")
public class TeacherAction extends BaseAction implements ModelDriven<Teacher>{
private static final long serialVersionUID = 1L;
//==========model==============
private Teacher teacher;
@Override
public Teacher getModel() {
if(teacher==null) teacher = new Teacher();
return teacher;
}
//==========model==============
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private TeacherService teacherService;
@Autowired
private XkService xkService;
@Autowired
private TeacherClassService teacherClassService;
@Autowired
private ClassRoomService classRoomService;
//依赖注入 end dao/service/===
//-------------------------华丽分割线---------------------------------------------
//============自定义参数start=============
private Integer [] bjs;
//============自定义参数end=============
//-------------------------华丽分割线---------------------------------------------
//============文件上传start=======================================================
private File file;
public Integer[] getBjs() {
return bjs;
}
public void setBjs(Integer[] bjs) {
this.bjs = bjs;
}
//提交过来的file的名字
private String fileFileName;
//提交过来的file的MIME类型
private String fileContentType;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
//============文件上传end=========================================================
public String jsonAction() {
// dataMap中的数据将会被Struts2转换成JSON字符串,所以这里要先清空其中的数据
jsonMap.clear();
jsonMap.put("success", true);
return JSON_TYPE;
}
//-------------------------华丽分割线---------------------------------------------//
//=============公=======共=======方=======法==========区=========start============//
/**
* 列表分页查询
*/
public String teacher(){
Map<String,Object> alias = new HashMap<String,Object>();
StringBuffer sb = new StringBuffer();
sb = sb.append("from Teacher where 1=1 and isDelete = 0 ");
if(teacher!=null && teacher.getRealName() !=null && !"".equals(teacher.getRealName())){
sb.append(" and realName like :realName ");
alias.put("realName", "%" +teacher.getRealName()+ "%" );
}
sb = sb.append("order by id desc");
Pager<Teacher> pagers = teacherService.findByAlias(sb.toString(),alias);
ActionContext.getContext().put("pagers", pagers);
ActionContext.getContext().put("Obj", teacher);
return SUCCESS;
}
/**
* 跳转到添加页面
* @return
*/
public String add(){
List<Xk> xkList = xkService.listByAlias("from Xk ", null);
List<ClassRoom> classList = classRoomService.listByAlias("from ClassRoom where isDelete = 0", null);
getActionContext().put("xkList", xkList);
getActionContext().put("classList", classList);
return SUCCESS;
}
/**
* 执行添加
* @return
*/
public String exAdd(){
teacher.setIsDelete(0);
teacher.setPassWrd("111111");
teacherService.save(teacher);
if(!isEmpty(bjs)){
for(Integer bj: bjs){
TeacherClass t = new TeacherClass();
ClassRoom c= new ClassRoom();
c.setId(bj);
t.setClassroom(c);
t.setTeacher(teacher);
teacherClassService.save(t);
}
}
ActionContext.getContext().put("url", "/teacher_teacher.do");
return "redirect";
}
/**
* 查看详情页面
* @return
*/
public String view(){
Teacher n = teacherService.getById(teacher.getId());
ActionContext.getContext().put("Obj", n);
return SUCCESS;
}
/**
* 跳转修改页面
* @return
*/
public String update(){
List<Xk> xkList = xkService.listByAlias("from Xk ", null);
List<ClassRoom> classList = classRoomService.listByAlias("from ClassRoom where isDelete = 0", null);
List<TeacherClass> checkList = teacherClassService.listByAlias("from TeacherClass where teacher.id="+teacher.getId(), null);
List<Integer> ids = new ArrayList<Integer>();
List<ClassRoomDto> ls = new ArrayList<ClassRoomDto>();
if(!isEmpty(checkList)){
for(TeacherClass t : checkList){
ids.add(t.getClassroom().getId());
}
}
if(!isEmpty(classList)){
for(ClassRoom c : classList){
ClassRoomDto cd = new ClassRoomDto();
if(!isEmpty(ids)){
if(ids.contains(c.getId())){
cd.setIsCheck(1);
}
}
cd.setClassRoom(c);
ls.add(cd);
}
}
getActionContext().put("xkList", xkList);
getActionContext().put("ls", ls);
Teacher n = teacherService.getById(teacher.getId());
ActionContext.getContext().put("Obj", n);
return SUCCESS;
}
/**
* 执行修改
* @return
*/
public String exUpdate(){
Teacher n = teacherService.getById(teacher.getId());
n.setRealName(teacher.getRealName());
n.setUserName(teacher.getUserName());
n.setXk(teacher.getXk());
//删除教师和课程关系
List<TeacherClass> checkList = teacherClassService.listByAlias("from TeacherClass where teacher.id="+teacher.getId(), null);
if(!isEmpty(checkList)){
for(TeacherClass t : checkList){
teacherClassService.delete(t.getId());
}
}
//新增新的
if(!isEmpty(bjs)){
for(Integer bj: bjs){
TeacherClass t = new TeacherClass();
ClassRoom c= new ClassRoom();
c.setId(bj);
t.setClassroom(c);
t.setTeacher(teacher);
teacherClassService.save(t);
}
}
teacherService.update(n);
ActionContext.getContext().put("url", "/teacher_teacher.do");
return "redirect";
}
/**
* 删除
* @return
*/
public String delete(){
Teacher n = teacherService.getById(teacher.getId());
n.setIsDelete(1);
teacherService.update(n);
ActionContext.getContext().put("url", "/teacher_teacher.do");
return "redirect";
}
//=============公=======共=======方=======法==========区=========end============//
//-------------------------华丽分割线---------------------------------------------//
//=============自=======定=======义=========方=======法==========区=========start============//
//=============自=======定=======义=========方=======法==========区=========end============//
}
如果也想学习本系统,下面领取。关注并回复:098ssh