源码获取:博客首页 "资源" 里下载!
项目介绍
后端技术包含springboot+mybatis+spring security+mysql+redis
前端技术包含 semanticUI + thymeleaf模板引擎
使用教程
1. ?下载项目之后 等待maven安装对应jar包 2. ?自行下载redis 并按照资源包下的application.yml要求进行配置
3. ?自行安装MySQL数据库 执行资源包下的sql文件
使用说明
1. ?运行redis服务器 2. ?启动项目 3. ?访问localhost:8080
4. ?用户名:admin ?密码:admin
注意事项
若导出信息时报错,则需要设置mysql,设置方式如下:
SELECT @@sql_mode; 查看是否包含ONLY_FULL_GROUP_BY;若包含,则执行以下命令:
SET GLOBAL sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
执行完成后,再通过SELECT @@sql_mode; 来查看; ?
注意:该方法仅用于临时修改,重启mysql后,以上设置失效。
?
?
?
?
?用户管理控制层:
@Controller
@RequestMapping("admin/system/user")
public class UserController {
@Autowired
UserService userService;
@Autowired
RoleService roleService;
@Autowired
UploadService uploadService;
@RequestMapping("list")
@SysLog("跳转系统用户列表页面")
public String list(){
return "admin/user/list";
}
@RequiresPermissions("sys:user:list")
@PostMapping("list")
@ResponseBody
public PageData<User> list(@RequestParam(value = "page",defaultValue = "1")Integer page,
@RequestParam(value = "limit",defaultValue = "10")Integer limit,
ServletRequest request){
Map map = WebUtils.getParametersStartingWith(request, "s_");
PageData<User> userPageData = new PageData<>();
QueryWrapper<User> userWrapper = new QueryWrapper<>();
if(!map.isEmpty()){
String type = (String) map.get("type");
if(StringUtils.isNotBlank(type)) {
userWrapper.eq("is_admin", "admin".equals(type) ? true : false);
}
String keys = (String) map.get("key");
if(StringUtils.isNotBlank(keys)) {
userWrapper.and(wrapper -> wrapper.like("login_name", keys).or().like("tel", keys).or().like("email", keys));
}
}
IPage<User> userPage = userService.page(new Page<>(page,limit),userWrapper);
userPageData.setCount(userPage.getTotal());
userPageData.setData(userPage.getRecords());
return userPageData;
}
@RequestMapping("add")
public String add(ModelMap modelMap){
List<Role> roleList = roleService.selectAll();
modelMap.put("roleList",roleList);
return "admin/user/add";
}
@RequiresPermissions("sys:user:add")
@PostMapping("add")
@ResponseBody
@SysLog("保存新增系统用户数据")
public ResponseEntity add(@RequestBody User user){
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
if(user.getRoleLists() == null || user.getRoleLists().size() == 0){
return ResponseEntity.failure("用户角色至少选择一个");
}
if(userService.userCount(user.getLoginName())>0){
return ResponseEntity.failure("登录名称已经存在");
}
// if(StringUtils.isNotBlank(user.getEmail())){
// if(userService.userCount(user.getEmail())>0){
// return ResponseEntity.failure("该邮箱已被使用");
// }
// }
// if(StringUtils.isNoneBlank(user.getTel())){
// if(userService.userCount(user.getTel())>0){
// return ResponseEntity.failure("该手机号已被绑定");
// }
// }
//设置默认密码
if(StringUtils.isBlank(user.getPassword())){
user.setPassword(Constants.DEFAULT_PASSWORD);
}
userService.saveUser(user);
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("保存用户信息出错");
}
//保存用户角色关系
userService.saveUserRoles(user.getId(),user.getRoleLists());
return ResponseEntity.success("操作成功");
}
@RequestMapping("edit")
public String edit(String id,ModelMap modelMap){
User user = userService.findUserById(id);
String roleIds = "";
if(user != null) {
roleIds = user.getRoleLists().stream().map(role -> role.getId()).collect(Collectors.joining(","));
}
List<Role> roleList = roleService.selectAll();
modelMap.put("localuser",user);
modelMap.put("roleIds",roleIds);
modelMap.put("roleList",roleList);
return "admin/user/edit";
}
@RequiresPermissions("sys:user:edit")
@PostMapping("edit")
@ResponseBody
@SysLog("保存系统用户编辑数据")
public ResponseEntity edit(@RequestBody User user){
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("用户ID不能为空");
}
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
if(user.getRoleLists() == null || user.getRoleLists().size() == 0){
return ResponseEntity.failure("用户角色至少选择一个");
}
User oldUser = userService.findUserById(user.getId());
if(StringUtils.isNotBlank(user.getEmail())){
if(!user.getEmail().equals(oldUser.getEmail())){
if(userService.userCount(user.getEmail())>0){
return ResponseEntity.failure("该邮箱已被使用");
}
}
}
if(StringUtils.isNotBlank(user.getLoginName())){
if(!user.getLoginName().equals(oldUser.getLoginName())) {
if (userService.userCount(user.getLoginName()) > 0) {
return ResponseEntity.failure("该登录名已存在");
}
}
}
if(StringUtils.isNotBlank(user.getTel())){
if(!user.getTel().equals(oldUser.getTel())) {
if (userService.userCount(user.getTel()) > 0) {
return ResponseEntity.failure("该手机号已经被绑定");
}
}
}
user.setIcon(oldUser.getIcon());
userService.updateUser(user);
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("保存用户信息出错");
}
userService.saveUserRoles(user.getId(),user.getRoleLists());
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:lock")
@PostMapping("lock")
@ResponseBody
@SysLog("锁定或开启系统用户")
public ResponseEntity lock(@RequestParam(value = "id",required = false)String id){
if(StringUtils.isBlank(id)){
return ResponseEntity.failure("参数错误");
}
User user = userService.getById(id);
if(user == null){
return ResponseEntity.failure("用户不存在");
}
userService.lockUser(user);
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:delete")
@PostMapping("delete")
@ResponseBody
@SysLog("删除系统用户数据(单个)")
public ResponseEntity delete(@RequestParam(value = "id",required = false)String id){
if(StringUtils.isBlank(id)){
return ResponseEntity.failure("参数错误");
}
User user = userService.getById(id);
if(user == null){
return ResponseEntity.failure("用户不存在");
}else if(user.getAdminUser()) {
return ResponseEntity.failure("不能删除后台用户");
}
userService.deleteUser(user);
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:delete")
@PostMapping("deleteSome")
@ResponseBody
@SysLog("删除系统用户数据(多个)")
public ResponseEntity deleteSome(@RequestBody List<User> users){
if(users == null || users.size()==0){
return ResponseEntity.failure("请选择需要删除的用户");
}
for (User u : users){
if(u.getAdminUser()){
return ResponseEntity.failure("不能删除超级管理员");
}else{
userService.deleteUser(u);
}
}
return ResponseEntity.success("操作成功");
}
@RequestMapping("userinfo")
public String toEditMyInfo(ModelMap modelMap){
String userId = MySysUser.id();
User user = userService.findUserById(userId);
modelMap.put("userinfo",user);
modelMap.put("userRole",user.getRoleLists());
return "admin/user/userInfo";
}
@SysLog("系统用户个人信息修改")
@PostMapping("saveUserinfo")
@ResponseBody
public ResponseEntity saveUserInfo(User user){
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("用户ID不能为空");
}
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
User oldUser = userService.findUserById(user.getId());
if(StringUtils.isNotBlank(user.getEmail())){
if(!user.getEmail().equals(oldUser.getEmail())){
if(userService.userCount(user.getEmail())>0){
return ResponseEntity.failure("该邮箱已被使用");
}
}
}
if(StringUtils.isNotBlank(user.getTel())){
if(!user.getTel().equals(oldUser.getTel())) {
if (userService.userCount(user.getTel()) > 0) {
return ResponseEntity.failure("该手机号已经被绑定");
}
}
}
userService.updateById(user);
return ResponseEntity.success("操作成功");
}
@RequestMapping("changePassword")
public String changePassword(ModelMap modelMap){
modelMap.put("currentUser",userService.getById(MySysUser.id()));
return "admin/user/changePassword";
}
@CrossOrigin
@SysLog("用户修改密码")
@PostMapping("changePassword")
@ResponseBody
public ResponseEntity changePassword(@RequestParam(value = "userName",required = false)String userName,
@RequestParam(value = "oldPwd",required = false)String oldPwd,
@RequestParam(value = "newPwd",required = false)String newPwd,
@RequestParam(value = "confirmPwd",required = false)String confirmPwd){
if(StringUtils.isBlank(oldPwd)){
return ResponseEntity.failure("旧密码不能为空");
}
if(StringUtils.isBlank(newPwd)){
return ResponseEntity.failure("新密码不能为空");
}
if(StringUtils.isBlank(confirmPwd)){
return ResponseEntity.failure("确认密码不能为空");
}
if(!confirmPwd.equals(newPwd)){
return ResponseEntity.failure("确认密码与新密码不一致");
}
//小程序修改密码
if(StringUtils.isBlank(userName)){
//PC修改密码
User user = userService.findUserById(MySysUser.id());
byte[] hashPassword = Encodes.sha1(oldPwd.getBytes(), Encodes.SHA1, Encodes.decodeHex(user.getSalt()), Constants.HASH_INTERATIONS);
String password = Encodes.encodeHex(hashPassword);
if(!user.getPassword().equals(password)){
return ResponseEntity.failure("旧密码错误");
}
user.setPassword(newPwd);
Encodes.entryptPassword(user);
userService.updateById(user);
return ResponseEntity.success("操作成功");
}else {
//小程序修改密码
User user = userService.findUserByLoginName(userName);
byte[] hashPassword = Encodes.sha1(oldPwd.getBytes(), Encodes.SHA1, Encodes.decodeHex(user.getSalt()), Constants.HASH_INTERATIONS);
String password = Encodes.encodeHex(hashPassword);
if(!user.getPassword().equals(password)){
return ResponseEntity.failure("旧密码错误");
}
user.setPassword(newPwd);
Encodes.entryptPassword(user);
userService.updateById(user);
return ResponseEntity.success("操作成功");
}
}
@SysLog("上传头像")
@PostMapping("uploadFace")
@ResponseBody
public ResponseEntity uploadFile(@RequestParam("icon") MultipartFile file, HttpServletRequest httpServletRequest) {
if(file == null){
return ResponseEntity.failure("上传文件为空 ");
}
String url = null;
Map map = new HashMap();
try {
url = uploadService.upload(file);
map.put("url", url);
map.put("name", file.getOriginalFilename());
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.failure(e.getMessage());
}
return ResponseEntity.success("操作成功").setAny("data",map);
}
}
学生管理控制层:
@Controller
public class StudentController extends BaseController {
@Autowired
private StudentService studentService;
// 跳转学生查询页面
@RequestMapping("/selectStudent")
public String selectStudent(){
return "view/student/selStudent";
}
// 查询所有学生
@RequestMapping("selStudent")
@ResponseBody
public LayuiResult<Map> selectStu(pageCount pageCount, StudentVO studentVO){
LayuiResult<Map> result = new LayuiResult<>();
List<Map> list = studentService.selStudent(studentVO,pageCount);
int count = studentService.selCount(studentVO);
result.setData(list);
result.setCount(count);
return result;
}
// 查询所有专业
@RequestMapping("selDepartment")
@ResponseBody
public LayuiResult<Map> selDepartment(){
List<DepartmentDB> selDepartment = studentService.selDepartment();
LayuiResult result = new LayuiResult();
result.setData(selDepartment);
return result;
}
// 根据系部查询专业
@RequestMapping("selectdid")
@ResponseBody
public LayuiResult<Map> selMajorDB(Integer did){
List<MajorDB> major =studentService.selMajorDB(did);
LayuiResult result = new LayuiResult();
result.setData(major);
return result;
}
// 根据专业查询年级
@RequestMapping("selectmid")
@ResponseBody
public LayuiResult<Map> selGradeDB(Integer mid){
List<GradeDB> grade = studentService.selGradeDB(mid);
LayuiResult result = new LayuiResult();
result.setData(grade);
return result;
}
// 根据年级查询班级
@RequestMapping("selectgid")
@ResponseBody
public LayuiResult<Map> selClassinfoDB(Integer gid){
List<ClassinfoDB> classinfo = studentService.selClassinfoDB(gid);
LayuiResult result = new LayuiResult();
result.setData(classinfo);
return result;
}
// 根据id查询一条学生信息以此进行修改
@RequestMapping("/selStudentId")
public String selStudentId(Integer id, Model model){
// 查询学生信息
List<StudentDB> stu = studentService.selStudentId(id);
// 查询班级
List<ClassinfoDB> cls = studentService.selClass();
// 查询政治面貌表
List<PoliticsTypeDB> stupol = studentService.selPolitics();
model.addAttribute("stu",stu);
model.addAttribute("cls",cls);
model.addAttribute("stupol",stupol);
return "view/student/updStudent";
}
// 根据id查询显示学生详细信息
@RequestMapping("/selectMessage")
public String selectMessage(Integer id, Model model){
// 查询学生信息
List<StudentDB> stu = studentService.selStudentId(id);
// 查询班级
List<ClassinfoDB> cls = studentService.selClass();
// 查询政治面貌表
List<PoliticsTypeDB> stupol = studentService.selPolitics();
model.addAttribute("stu",stu);
model.addAttribute("cls",cls);
model.addAttribute("stupol",stupol);
return "view/student/selStuExam";
}
// 修改用户信息
@RequestMapping("/updateStudent")
@ResponseBody
public LayuiResult<StudentDB> updateStudent(StudentDB studentDB, String birthday) throws Exception{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date=format.parse(birthday);
studentDB.setSbirthday(date);
studentService.updateStudent(studentDB);
LayuiResult result= new LayuiResult();
//删除提示
result.setMsg("修改成功!");
return result;
}
}
课程管理控制层:?
@Controller
public class SelCourseManController {
@Autowired
private SelCourseManageService selCourseManageService;
@RequestMapping("selCourses")
public String selCourses(){
System.out.println("----------------------");
return "SelCourseMan";
}
@RequestMapping("selSc")
@ResponseBody
public Object selSc(Integer page, Integer limit, StuCourseVO stuCourseVO){
System.out.println(stuCourseVO.getSname());
PageHelper.startPage(page, limit);
List<StuCourseVO> stuCourseVOS = selCourseManageService.selSc(stuCourseVO);
PageInfo pageInfo = new PageInfo(stuCourseVOS);
Map<String, Object> tableData = new HashMap<String, Object>();
//这是layui要求返回的json数据格式
tableData.put("code", 0);
tableData.put("msg", "");
//将全部数据的条数作为count传给前台(一共多少条)
tableData.put("count", pageInfo.getTotal());
//将分页后的数据返回(每页要显示的数据)
tableData.put("data", pageInfo.getList());
// System.out.print(cs);
return tableData;
}
//下面是下拉框
@RequestMapping("selDe")
@ResponseBody
public Object selDe(){
List<DepartmentDB> departmentDBS = selCourseManageService.selDe();
//System.out.println(departmentDBS);
return departmentDBS;
}
@RequestMapping("selMa")
@ResponseBody
public Object selMa(Integer did){
//System.out.println(did);
List<MajorDB> majors = selCourseManageService.selMa(did);
//System.out.println(majors);
return majors;
}
@RequestMapping("selGr")
@ResponseBody
public Object selGr(Integer mid){
//System.out.println(mid);
List<GradeDB> gradeDBS = selCourseManageService.selGr(mid);
// System.out.println(gradeDBS);
return gradeDBS;
}
@RequestMapping("selCl")
@ResponseBody
public Object selCl(Integer gid){
// System.out.println(gid);
List<ClassinfoDB> classinfoDBS = selCourseManageService.selClass(gid);
// System.out.println(classinfoDBS);
return classinfoDBS;
}
@RequestMapping("selSt")
@ResponseBody
public Object selSt(Integer classid){
//System.out.println(classid);
List<StudentDB> studentDBS = selCourseManageService.selSt(classid);
// System.out.println(studentDBS);
return studentDBS;
}
@RequestMapping("selCo")
@ResponseBody
public Object selCo(){
//System.out.println(classid);
List<CourseDB> courseDBS = selCourseManageService.selCo();
// System.out.println(studentDBS);
return courseDBS;
}
//退课
@RequestMapping("dropCous")
@ResponseBody
public Object dropCous(Integer sid,Integer cid){
int dropcou = selCourseManageService.dropcou(sid, cid);
int updatecou = selCourseManageService.updatecou(cid);
if(dropcou>0 && updatecou>0){
return "退课成功";
}else{
return "退课失败,请稍后再试或联系管理员";
}
}
//换课
@RequestMapping("changesCou")
@ResponseBody
public Object changesCou( Integer ccd, Integer sid,Integer cid) {
/*System.out.println(ccd+"8888888");
System.out.println(sid+"-----"+cid);*/
int i = selCourseManageService.selStc(ccd, sid);
if (i > 0) {
return "该学生已经选过这门课";
} else {
int dropcou = selCourseManageService.changesCou(ccd, sid, cid);
if (dropcou > 0) {
return "换课成功";
} else {
return "退课失败,请稍后再试或联系管理员";
}
}
}
}
源码获取:博客首页 "资源" 里下载!
|