基于SSM實(shí)現(xiàn)學(xué)生管理系統(tǒng)
本文實(shí)例為大家分享了SSM實(shí)現(xiàn)學(xué)生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
概述
基于Spring + Spring MVC 的學(xué)生管理系統(tǒng),使用Maven進(jìn)行包管理。
主要代碼
@RequestMapping("/student") @Controller public class StudentController { @Autowired private StudentService studentService; @Autowired private ClazzService clazzService; /** * 學(xué)生列表頁 * @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; } /** * 獲取學(xué)生列表 * @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())){ //說明是學(xué)生 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; } /** * 編輯學(xué)生信息 * @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", "學(xué)生姓名不能為空!"); return ret; } if(StringUtils.isEmpty(student.getPassword())){ ret.put("type", "error"); ret.put("msg", "學(xué)生登錄密碼不能為空!"); return ret; } if(student.getClazzId() == null){ ret.put("type", "error"); ret.put("msg", "請(qǐng)選擇所屬班級(jí)!"); 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", "學(xué)生添加失??!"); return ret; } ret.put("type", "success"); ret.put("msg", "學(xué)生修改成功!"); return ret; } /** * 添加學(xué)生信息 * @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", "學(xué)生姓名不能為空!"); return ret; } if(StringUtils.isEmpty(student.getPassword())){ ret.put("type", "error"); ret.put("msg", "學(xué)生登錄密碼不能為空!"); return ret; } if(student.getClazzId() == null){ ret.put("type", "error"); ret.put("msg", "請(qǐng)選擇所屬班級(jí)!"); 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", "學(xué)生添加失??!"); return ret; } ret.put("type", "success"); ret.put("msg", "學(xué)生添加成功!"); return ret; } /** * 刪除學(xué)生信息 * @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", "請(qǐng)選擇要?jiǎng)h除的數(shù)據(jù)!"); 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", "該學(xué)生下存在其他信息,請(qǐng)勿沖動(dòng)!"); return ret; } ret.put("type", "success"); ret.put("msg", "學(xué)生刪除成功!"); 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", "請(qǐng)選擇文件!"); return ret; } if(photo.getSize() > 10485760){ //文件沒有選擇 ret.put("type", "error"); ret.put("msg", "文件大小超過10M,請(qǐng)上傳小于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", "文件格式不正確,請(qǐng)上傳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();//如果不存在,則創(chuàng)建一個(gè)文件夾upload } //把文件轉(zhuǎn)存到這個(gè)文件夾下 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; } }
運(yùn)行配置
1、首先安裝Mysql5.7,設(shè)置用戶名為root,密碼為root,并保證其在運(yùn)行狀態(tài),并執(zhí)行sql文件導(dǎo)入數(shù)據(jù)。
2、然后再配置Maven到環(huán)境變量中,在源代碼目錄下運(yùn)行
3、使用瀏覽器訪問http://localhost:8080即可進(jìn)入系統(tǒng)。
功能展示
1. 首頁登陸
2.2 管理
2.3 管理
2.4 管理
2.5 管理
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java+Mysql學(xué)生管理系統(tǒng)源碼
- java學(xué)生管理系統(tǒng)界面簡(jiǎn)單實(shí)現(xiàn)(全)
- 簡(jiǎn)單實(shí)現(xiàn)Android學(xué)生管理系統(tǒng)(附源碼)
- 簡(jiǎn)單實(shí)現(xiàn)Java版學(xué)生管理系統(tǒng)
- Java基于MySQL實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- Java實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- java設(shè)計(jì)簡(jiǎn)單學(xué)生管理系統(tǒng)
- JDBC+GUI實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)
- java實(shí)現(xiàn)學(xué)生管理系統(tǒng)(面向?qū)ο?
- JDBC實(shí)現(xiàn)學(xué)生管理系統(tǒng)
相關(guān)文章
Spring自帶定時(shí)任務(wù)@Scheduled注解實(shí)例講解
這篇文章主要介紹了Spring自帶定時(shí)任務(wù)@Scheduled注解的相關(guān)知識(shí),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-06-06springBoot 創(chuàng)建定時(shí)任務(wù)過程詳解
這篇文章主要介紹了springBoot 創(chuàng)建定時(shí)任務(wù)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10springboot整合activity自動(dòng)部署及部署文件命名流程
這篇文章主要介紹了springboot整合activity自動(dòng)部署及部署文件命名流程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09CompletableFuture并行處理List分批數(shù)據(jù)demo
這篇文章主要介紹了CompletableFuture并行處理List分批數(shù)據(jù)實(shí)現(xiàn)實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11?Java數(shù)據(jù)結(jié)構(gòu)的十大排序
這篇文章主要介紹了?Java數(shù)據(jù)結(jié)構(gòu)的十大排序,排序算法分為比較類排序和非比較類排序,具體的內(nèi)容,需要的朋友參考下面思維導(dǎo)圖及文章介紹,希望對(duì)你有所幫助2022-01-01Java將對(duì)象保存到文件中/從文件中讀取對(duì)象的方法
下面小編就為大家?guī)硪黄狫ava將對(duì)象保存到文件中/從文件中讀取對(duì)象的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12java Callable與Future的詳解及實(shí)例
這篇文章主要介紹了java Callable與Future的詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-01-01