1.包含源程序,数据库脚本。代码和数据库脚本都有详细注释。
2.课题设计仅供参考学习使用,可以在此基础上进行扩展完善
代码已经上传github,下载地址:https://github.com/21503882/stuchoosecourse
开发环境:
Eclipse ,MYSQL,JDK1.8,Tomcat 8.5
涉及技术点:
MVC模式、SpringBoot、Mybatis、Redis、HTML、log4j、druid、Bootstrap、
Semantic UI、Thymeleaf、JavaScript、CSS、JQUERY、Ajax等
适合学习J2EE的一段时间的熟手,代码思路清晰,注解详细,数据库用的是mysql5.1,服务器用的tomcat8.5,JDK版本1.8. 编程软件Eclispe J2EE版本。是典型MVC架构,并且前后台分离
4.2.1 教师子系统功能结构图
教师子系统主要完成教师开课申请,教师课程查看,学生成绩录入,留言板管理等功能。教师子系统功能结构如图4-1。
图4-1 教师子系统模块图
4.2.2 管理员子系统功能结构图
管理员子系统完成此系统的管理维护操作,主要包括用户信息管理模块,学生信息管理模块,开设课程管理模块,教师课程一审模块,学生选课一审模块,留言板模块。管理员子系统的的功能结图如图4-2所示:
图 4-2 管理员子系统模块
4.2.3 领导子系统功能结构图
领导子系统主要完成对开设课程的二审,学生选课的二审,开设课程管理及留言板的管理功能。领导子系统的的功能结图如图4-3所示:
图 4-3 领导子系统模块
4.2.4 学生子系统功能结构图
学生子系统主要完成课程申请的功能,已申请的课程的成绩查看的功能,留言板的功能等。学生管理子系统的的功能结图如图4-4所示:
图 4-4 学生子系统模块
5.3 教师操作子系统的实施
图5-4 开课申请模块
图5-5我的课程模块
图5-6 学生成绩管理页面
5.4 管理员子系统的实施
图5-7用户管理
图5-10学生选课一审模块
图5-10留言管理模块
5.5 领导操作子系统的实施
图5-11 教师开课二审模块
图5-12 学生选课二审页面
5.6 学生子系统的实施
图5-13 学生选课申请模块
图5-14 已申请课程查看页面
图5-15 留言管理页面
package com.extr.controller;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.extr.controller.domain.Message;
import com.extr.domain.question.Field;
import com.extr.domain.user.User;
import com.extr.security.UserInfo;
import com.extr.service.QuestionService;
import com.extr.service.UserService;
import com.extr.util.Page;
import com.extr.util.PagingUtil;
import com.extr.util.StandardPasswordEncoderForSha1;
@Controller
public class UserController {
public static final String SUCCESS_MESSAGE = "success";
public static final String ERROR_MESSAGE = "failed";
@Autowired
private UserService userService;
@Autowired
private QuestionService questionService;
/**
* 用户登录页面
*
* @return
*/
@RequestMapping(value = { "/user-login-page" }, method = RequestMethod.GET)
public String loginPage(Model model, @RequestParam(value = "result", required = false, defaultValue = "") String result) {
if("failed".equals(result)){
model.addAttribute("result", "无效的用户名或者密码");
}
return "login";
}
/**
* 用户登录
*
* @param user
* @return
*/
@RequestMapping(value = { "/user-login" }, method = RequestMethod.POST)
public @ResponseBody
Message userLogin(@RequestBody User user) {
user.setCreate_date(new Date());
Message message = new Message();
try {
userService.addUser(user);
} catch (Exception e) {
// TODO Auto-generated catch block
message.setResult("error");
e.printStackTrace();
}
return message;
}
/**
* 用户登录成功页面
*
* @return
*/
@RequestMapping(value = { "/regist-success/{username}" }, method = RequestMethod.GET)
public String registerSuccessPage(@PathVariable String username, Model model) {
model.addAttribute("username", username);
return "regist-success";
}
/**
* 用户信息查看
*
* @return
*/
@RequestMapping(value = { "/user-detail/{username}" }, method = RequestMethod.GET)
public String userDetailPage(@PathVariable String username, Model model) {
UserInfo userInfo = (UserInfo) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
Boolean isAdmin = userService.isExistUserRoleById(1, userInfo.getUserid());
model.addAttribute("username", username);
if(isAdmin){
return "redirect:/admin/usercenter";
}
return "redirect:/student/usercenter";
}
/**
* 用户注册页面
*
* @return
*/
@RequestMapping(value = { "/user-register" }, method = RequestMethod.GET)
public String registerPage(Model model) {
List
model.addAttribute("fieldList", fieldList);
return "register";
}
/**
* 用户注册
*
* @param user
* @return
*/
@RequestMapping(value = { "/user-reg" }, method = RequestMethod.POST)
public @ResponseBody
Message userRegister(@RequestBody User user) {
user.setCreate_date(new Date());
String password = user.getPassword() + "{" + user.getUsername() + "}";
PasswordEncoder passwordEncoder = new StandardPasswordEncoderForSha1();
String resultPassword = passwordEncoder.encode(password);
user.setPassword(resultPassword);
user.setEnabled("1");
Message message = new Message();
try {
userService.addUser(user);
} catch (Exception e) {
// TODO Auto-generated catch block
if(e.getMessage().equals("duplicate-username")){
message.setResult(e.getMessage());
message.setMessageInfo("用户名:" + user.getUsername() + "已经存在");
}else
message.setResult("错误!" + e.getClass().getName());
e.printStackTrace();
}
return message;
}
/**
* 修改密码页面
*
* @return
*/
@RequestMapping(value = { "student/change-password" }, method = RequestMethod.GET)
public String changePasswordPage() {
return "student/change-password";
}
@RequestMapping(value = { "change-pwd" }, method = RequestMethod.POST)
public @ResponseBody Message changePassword(@RequestBody User user){
Message message = new Message();
UserInfo userInfo = (UserInfo) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
try{
String password = user.getPassword() + "{" + userInfo.getUsername() + "}";
PasswordEncoder passwordEncoder = new StandardPasswordEncoderForSha1();
String resultPassword = passwordEncoder.encode(password);
user.setPassword(resultPassword);
user.setUsername(userInfo.getUsername());
userService.updateUser(user, null);
System.out.println(user.getFieldId());
}catch(Exception e){
e.printStackTrace();
message.setResult(e.getClass().getName());
}
return message;
}
/**
* 修改密码页面
*
* @return
*/
@RequestMapping(value = { "student/setting" }, method = RequestMethod.GET)
public String settingPage(Model model) {
UserInfo userInfo = (UserInfo) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
User user = userService.getUserById(userInfo.getUserid());
model.addAttribute("user", user);
return "student/setting";
}
@RequestMapping(value = { "setting" }, method = RequestMethod.POST)
public @ResponseBody Message setting(@RequestBody User user){
Message message = new Message();
try{
userService.updateUser(user, null);
}catch(Exception e){
e.printStackTrace();
message.setResult(e.getClass().getName());
}
return message;
}
/**
* 显示用户管理界面
*
* @return
*/
@RequestMapping(value = { "admin/user-list" }, method = RequestMethod.GET)
public String showUserListPage(Model model, HttpServletRequest request) {
int index = 1;
if(request.getParameter("page") != null)
index = Integer.parseInt(request.getParameter("page"));
Page
page.setPageNo(index);
page.setPageSize(20);
List
String pageStr = PagingUtil.getPagelink(index, page.getTotalPage(), "", "admin/user-list");
model.addAttribute("userList", userList);
model.addAttribute("pageStr", pageStr);
return "admin/user-list";
}
/**
* 添加用户界面
* @param model
* @param request
* @return
*/
@RequestMapping(value = "/admin/add-user", method = RequestMethod.GET)
private String addUserPage(Model model, HttpServletRequest request) {
List
model.addAttribute("fieldList", fieldList);
return "admin/add-user";
}
/**
* 添加用户
* @param user
* @return
*/
@RequestMapping(value = { "/admin/add-user" }, method = RequestMethod.POST)
public @ResponseBody Message addUser(@RequestBody User user){
user.setCreate_date(new Date());
String password = user.getPassword() + "{" + user.getUsername() + "}";
PasswordEncoder passwordEncoder = new StandardPasswordEncoderForSha1();
String resultPassword = passwordEncoder.encode(password);
user.setPassword(resultPassword);
user.setEnabled("1");
Message message = new Message();
try {
userService.addUser(user);
} catch (Exception e) {
// TODO Auto-generated catch block
if(e.getMessage().equals("duplicate-username")){
message.setResult(e.getMessage());
message.setMessageInfo("用户名:" + user.getUsername() + "已经存在");
}else
message.setResult("错误!" + e.getClass().getName());
e.printStackTrace();
}
return message;
}
/**
* 禁用用户
* @param model
* @param request
* @return
*/
@RequestMapping(value = "/admin/disable-user/{userId}", method = RequestMethod.GET)
public @ResponseBody Message disableUser(Model model, HttpServletRequest request, @PathVariable Integer userId) {
Message message = new Message();
try{
User user = new User();
user.setId(userId);
user.setEnabled("0");
userService.updateUser(user, null);
}catch(Exception e){
e.printStackTrace();
message.setResult(e.getClass().getName());
}
return message;
}
/**
* 启用用户
* @param model
* @param request
* @return
*/
@RequestMapping(value = "/admin/enable-user/{userId}", method = RequestMethod.GET)
public @ResponseBody Message enableUser(Model model, HttpServletRequest request, @PathVariable Integer userId) {
Message message = new Message();
try{
User user = new User();
user.setId(userId);
user.setEnabled("1");
userService.updateUser(user, null);
}catch(Exception e){
e.printStackTrace();
message.setResult(e.getClass().getName());
}
return message;
}
}
代码已经上传github,下载地址:https://github.com/21503882/stuchoosecourse