这篇文章主要介绍“SSM管理系统的运行如何配置”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“SSM管理系统的运行如何配置”文章能帮助大家解决问题。
基于Spring + Spring MVC 的学生管理系统,使用Maven进行包管理。
@RequestMapping("/student") @Controller public class StudentController { @Autowired private StudentService studentService; @Autowired private ClazzService clazzService; /** * 学生列表页 * @param model * @return */ @RequestMapping(value="/list",method=RequestMethod.GET) public ModelAndView list(ModelAndView model){ model.setViewName("student/student_list"); List<Clazz> clazzList = clazzService.findAll(); model.addObject("clazzList",clazzList ); model.addObject("clazzListJson",JSONArray.fromObject(clazzList)); return model; } /** * 获取学生列表 * @param name * @param page * @return */ @RequestMapping(value="/get_list",method=RequestMethod.POST) @ResponseBody public Map<String, Object> getList( @RequestParam(value="name",required=false,defaultValue="") String name, @RequestParam(value="clazzId",required=false) Long clazzId, HttpServletRequest request, Page page ){ Map<String, Object> ret = new HashMap<String, Object>(); Map<String, Object> queryMap = new HashMap<String, Object>(); queryMap.put("username", "%"+name+"%"); Object attribute = request.getSession().getAttribute("userType"); if("2".equals(attribute.toString())){ //说明是学生 Student loginedStudent = (Student)request.getSession().getAttribute("user"); queryMap.put("username", "%"+loginedStudent.getUsername()+"%"); } if(clazzId != null){ queryMap.put("clazzId", clazzId); } queryMap.put("offset", page.getOffset()); queryMap.put("pageSize", page.getRows()); ret.put("rows", studentService.findList(queryMap)); ret.put("total", studentService.getTotal(queryMap)); return ret; } /** * 编辑学生信息 * @param clazz * @return */ @RequestMapping(value="/edit",method=RequestMethod.POST) @ResponseBody public Map<String, String> edit(Student student){ Map<String, String> ret = new HashMap<String, String>(); if(StringUtils.isEmpty(student.getUsername())){ ret.put("type", "error"); ret.put("msg", "学生姓名不能为空!"); return ret; } if(StringUtils.isEmpty(student.getPassword())){ ret.put("type", "error"); ret.put("msg", "学生登录密码不能为空!"); return ret; } if(student.getClazzId() == null){ ret.put("type", "error"); ret.put("msg", "请选择所属班级!"); return ret; } if(isExist(student.getUsername(), student.getId())){ ret.put("type", "error"); ret.put("msg", "该姓名已存在!"); return ret; } student.setSn(StringUtil.generateSn("S", "")); if(studentService.edit(student) <= 0){ ret.put("type", "error"); ret.put("msg", "学生添加失败!"); return ret; } ret.put("type", "success"); ret.put("msg", "学生修改成功!"); return ret; } /** * 添加学生信息 * @param student * @return */ @RequestMapping(value="/add",method=RequestMethod.POST) @ResponseBody public Map<String, String> add(Student student){ Map<String, String> ret = new HashMap<String, String>(); if(StringUtils.isEmpty(student.getUsername())){ ret.put("type", "error"); ret.put("msg", "学生姓名不能为空!"); return ret; } if(StringUtils.isEmpty(student.getPassword())){ ret.put("type", "error"); ret.put("msg", "学生登录密码不能为空!"); return ret; } if(student.getClazzId() == null){ ret.put("type", "error"); ret.put("msg", "请选择所属班级!"); return ret; } if(isExist(student.getUsername(), null)){ ret.put("type", "error"); ret.put("msg", "该姓名已存在!"); return ret; } student.setSn(StringUtil.generateSn("S", "")); if(studentService.add(student) <= 0){ ret.put("type", "error"); ret.put("msg", "学生添加失败!"); return ret; } ret.put("type", "success"); ret.put("msg", "学生添加成功!"); return ret; } /** * 删除学生信息 * @param ids * @return */ @RequestMapping(value="/delete",method=RequestMethod.POST) @ResponseBody public Map<String, String> delete( @RequestParam(value="ids[]",required=true) Long[] ids ){ Map<String, String> ret = new HashMap<String, String>(); if(ids == null || ids.length == 0){ ret.put("type", "error"); ret.put("msg", "请选择要删除的数据!"); return ret; } try { if(studentService.delete(StringUtil.joinString(Arrays.asList(ids), ",")) <= 0){ ret.put("type", "error"); ret.put("msg", "删除失败!"); return ret; } } catch (Exception e) { // TODO: handle exception ret.put("type", "error"); ret.put("msg", "该学生下存在其他信息,请勿冲动!"); return ret; } ret.put("type", "success"); ret.put("msg", "学生删除成功!"); return ret; } /** * 上传用户头像图片 * @param photo * @param request * @param response * @return * @throws IOException */ @RequestMapping(value="/upload_photo",method=RequestMethod.POST) @ResponseBody public Map<String, String> uploadPhoto(MultipartFile photo, HttpServletRequest request, HttpServletResponse response ) throws IOException{ Map<String, String> ret = new HashMap<String, String>(); if(photo == null){ //文件没有选择 ret.put("type", "error"); ret.put("msg", "请选择文件!"); return ret; } if(photo.getSize() > 10485760){ //文件没有选择 ret.put("type", "error"); ret.put("msg", "文件大小超过10M,请上传小于10M的图片!"); return ret; } String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf(".") + 1,photo.getOriginalFilename().length()); if(!"jpg,png,gif,jpeg".contains(suffix.toLowerCase())){ ret.put("type", "error"); ret.put("msg", "文件格式不正确,请上传jpg,png,gif,jpeg格式的图片!"); return ret; } String savePath = request.getServletContext().getRealPath("/") + "\\upload\\"; System.out.println(savePath); File savePathFile = new File(savePath); if(!savePathFile.exists()){ savePathFile.mkdir();//如果不存在,则创建一个文件夹upload } //把文件转存到这个文件夹下 String filename = new Date().getTime() + "." + suffix; photo.transferTo(new File(savePath + filename )); ret.put("type", "success"); ret.put("msg", "图片上传成功!"); ret.put("src", request.getServletContext().getContextPath() + "/upload/" + filename); return ret; } private boolean isExist(String username,Long id){ Student student = studentService.findByUserName(username); if(student != null){ if(id == null){ return true; } if(student.getId().longValue() != id.longValue()){ return true; } } return false; } }
(1)首先安装Mysql5.7,设置用户名为root,密码为root,并保证其在运行状态,并执行sql文件导入数据。
(2)然后再配置Maven到环境变量中,在源代码目录下运行
(3)使用浏览器访问http://localhost:8080即可进入系统。
关于“SSM管理系统的运行如何配置”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。