毕业设计|基于SSM+JSP的家校通管理系统(二)

简介: 毕业设计|基于SSM+JSP的家校通管理系统

毕业设计|基于SSM+JSP的家校通管理系统(一)https://developer.aliyun.com/article/1423936


四,核心代码展示

4.1 教室管理

@Controller
@RequestMapping("/classroom")
public class ClassroomController extends BaseController {
  /**
   * 依赖注入 start dao/service/===
   */
  @Autowired
  private ClassroomService classroomService;
  @Autowired
  private SchoolService  schoolService;
  @Autowired
  private GradeService gradeService;
  @Autowired
  private TeacherService teacherService;
  /**
   * 分页查询 返回list对象(通过对象)
   * 
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/findByObj.do")
  public String findByObj(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response,HttpSession session) {
    Pager<Classroom> pagers=new Pager<Classroom>();
    Integer schoolId = (Integer) session.getAttribute("schoolId");
    if(!isEmpty(classroom.getName())){
       Map<String, Object> map = getMap();
       map.put("name",classroom.getName());
       map.put("schoolId",schoolId);
      //模糊查询分页查询
       pagers = classroomService.findByMap(map);
    }else{
      classroom.setSchoolId(schoolId);
      //分页查询
      pagers = classroomService.findByEntity(classroom);
    }
    for (Classroom classroom1 : pagers.getDatas()) {
      Teacher obj = teacherService.load(classroom1.getId());
      if(obj!=null){
        classroom1.setTeacherName(obj.getRealName());     
        }
      Grade g=gradeService.load(classroom1.getGradeId());
      if(g!=null){
        classroom1.setGradeName(g.getName());
      }
    }
    model.addAttribute("pagers", pagers);
    //存储查询条件
    model.addAttribute("obj", classroom);
    return "classroom/classroom";
  }
  /**
   * 分页查询 返回list对象(通过Map)
   * 
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/findByMap.do")
  public String findByMap(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response,HttpSession session) {
    //通过map查询
    Map<String,Object> params = new HashMap<String,Object>();
        if(!isEmpty(classroom.getName())){
          params.put("name", classroom.getName());
    }
        if(!isEmpty(classroom.getGradeId())){
          params.put("gradeId", classroom.getGradeId());
    }
        if(!isEmpty(classroom.getIsDelete())){
          params.put("isDelete", classroom.getIsDelete());
    }
    //分页查询
    Pager<Classroom> pagers = classroomService.findByMap(params);
    model.addAttribute("pagers", pagers);
    //存储查询条件
    model.addAttribute("obj", classroom);
    return "classroom/classroom";
  }
  /**
   * 跳至添加页面
   * @return
   */
  @RequestMapping(value = "/add.do")
  public String add(Model model,HttpSession session) {
    Integer schoolId = (Integer) session.getAttribute("schoolId");
    School school=new School();
    school.setId(schoolId);
    List<School> schoolList=schoolService.listAllByEntity(school);
    model.addAttribute("schoolList", schoolList);
    return "classroom/add";
  }
  /**
   * 添加执行
   * @return
   */
  @RequestMapping(value = "/exAdd.do")
  public String exAdd(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response) {
    classroom.setIsDelete(0);
    classroom.setStatus(0);
    classroomService.insert(classroom);
    return "redirect:/classroom/findByObj.do";
  }
  /**
   * 跳至修改页面
   * @return
   */
  @RequestMapping(value = "/update.do")
  public String update(Integer id,Model model) {
    Classroom obj = classroomService.load(id);
    model.addAttribute("obj",obj);
    return "classroom/update";
  }
  /**
   * 添加修改
   * @return
   */
  @RequestMapping(value = "/exUpdate.do")
  public String exUpdate(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response) {
    classroomService.update(classroom);
    return "redirect:/classroom/findByObj.do";
  }
  /**
   * 删除通过主键
   * @return
   */
  @RequestMapping(value = "/delete.do")
  public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
    //真正删除
    classroomService.deleteById(id);
    //通过参数删除
        //Map<String,Object> params = new HashMap<String,Object>();
    //params.put("id", id);
    //classroomService.deleteBySqId("deleteBySql", params);
    //状态删除
    //Classroom load = classroomService.load(id);
    //load.setIsDelete(1);
    //classroomService.update(load);
    return "redirect:/classroom/findByObj.do";
  }
  // --------------------------------------- 华丽分割线 ------------------------------
  /**
   * 通过id查询 返回list json(通过map)
   * 
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/findByGradeId.json", produces=MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  @ResponseBody
  public String findByGradeId(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response) {
     Map<String, Object> map = getMap();
     map.put("gradeId",classroom.getGradeId());
     List<Classroom> classroomList =classroomService.list("listBySqlId", map);
    //分页查询
    JSONObject jsonObject = JsonUtil2.getJsonObject();
    jsonObject.put("obj", classroomList);
    return jsonObject.toString();
  }
  /**
   * 分页查询 返回list json(通过对象)
   * 
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/findByObj.json", produces=MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  @ResponseBody
  public String findByObjByEntity(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response) {
    //分页查询
    Pager<Classroom> pagers = classroomService.findByEntity(classroom);
    JSONObject jsonObject = JsonUtil2.getJsonObject();
    jsonObject.put("pagers", pagers);
    jsonObject.put("obj", classroom);
    return jsonObject.toString();
  }
  /**
   * 分页查询 返回list json(通过Map)
   * 
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/findByMap.json", produces=MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  @ResponseBody
  public String findByMapMap(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response) {
    //通过map查询
    Map<String,Object> params = new HashMap<String,Object>();
        if(!isEmpty(classroom.getName())){
          params.put("name", classroom.getName());
    }
        if(!isEmpty(classroom.getGradeId())){
          params.put("gradeId", classroom.getGradeId());
    }
        if(!isEmpty(classroom.getIsDelete())){
          params.put("isDelete", classroom.getIsDelete());
    }
    //分页查询
    Pager<Classroom> pagers = classroomService.findByMap(params);
    JSONObject jsonObject = JsonUtil2.getJsonObject();
    jsonObject.put("pagers", pagers);
    jsonObject.put("obj", classroom);
    return jsonObject.toString();
  }
  /**
   * ajax 添加
   * @param 
   * @return
   */
  @RequestMapping(value = "/exAdd.json", produces=MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  @ResponseBody
  public String exAddJson(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response) {
    classroomService.insert(classroom);
    JSONObject jsonObject = JsonUtil2.getJsonObject();
    jsonObject.put("message", "添加成功");
    return jsonObject.toString();
  }
  /**
   * ajax 修改
   * @param 
   * @return
   */
  @RequestMapping(value = "/exUpdate.json", produces=MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  @ResponseBody
  public String exUpdateJson(Classroom classroom, Model model, HttpServletRequest request, HttpServletResponse response) {
    classroomService.update(classroom);
    JSONObject jsonObject = JsonUtil2.getJsonObject();
    jsonObject.put("message", "修改成功");
    return jsonObject.toString();
  }
  /**
   * ajax 删除
   * @return
   */
  @RequestMapping(value = "/delete.json", produces=MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  @ResponseBody
  public String exDeleteJson(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
    //真正删除
    classroomService.deleteById(id);
    //通过参数删除
        //Map<String,Object> params = new HashMap<String,Object>();
    //params.put("id", id);
    //classroomService.deleteBySqId("deleteBySql", params);
    //状态删除
    //Classroom load = classroomService.load(id);
    //load.setIsDelete(1);
    //classroomService.update(load);
    JSONObject jsonObject = JsonUtil2.getJsonObject();
    jsonObject.put("message", "删除成功");
    return jsonObject.toString();
  }
  /**
   * 单文件上传
   * @param file
   * @param request
   * @param model
   * @return
   */
    @RequestMapping(value = "/saveFile")  
    public String saveFile(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, Model model) {  
        System.out.println("开始");  
        String path = request.getSession().getServletContext().getRealPath("/upload");  
        String fileName = file.getOriginalFilename();  
        System.out.println(path);  
        File targetFile = new File(path, fileName);  
        if(!targetFile.exists()){  
            targetFile.mkdirs();  
        }  
        //保存  
        try {  
            file.transferTo(targetFile);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return "";  
    }  
  /**
   * springMvc多文件上传
   * @param files
   * @param id
   * @return
   */
    @RequestMapping(value = "/saveFiles")
    public String saveFiles(@RequestParam("file") CommonsMultipartFile[] files,Integer id,HttpServletRequest request){
    for(int i = 0;i<files.length;i++){
          System.out.println("fileName---------->" + files[i].getOriginalFilename());
      if(!files[i].isEmpty()){
            int pre = (int) System.currentTimeMillis();
        try {
      //拿到输出流,同时重命名上传的文件
       String filePath = request.getRealPath("/upload");
       File f=new File(filePath);
       if(!f.exists()){
        f.mkdirs();
       }
         String fileNmae=new Date().getTime() + files[i].getOriginalFilename();
         File file=new File(filePath+"/"+pre + files[i].getOriginalFilename());
        if(!file.exists()){
          file.createNewFile();
       }
        files[i].transferTo(file);
         } catch (Exception e) {
        e.printStackTrace();
        System.out.println("上传出错");
       }
      }
    }
    return "";
  }
}


毕业设计|基于SSM+JSP的家校通管理系统(三)https://developer.aliyun.com/article/1423938

相关文章
|
5月前
|
Java 数据库连接 Maven
手把手教你如何搭建SSM框架、图书商城系统案例
这篇文章是关于如何搭建SSM框架以及实现一个图书商城系统的详细教程,包括了项目的配置文件整合、依赖管理、项目结构和运行效果展示,并提供了GitHub源码链接。
手把手教你如何搭建SSM框架、图书商城系统案例
|
4月前
|
Java 应用服务中间件 数据库连接
ssm项目整合,简单的用户管理系统
文章介绍了一个使用SSM框架(Spring、SpringMVC、MyBatis)构建的简单用户管理系统的整合过程,包括项目搭建、数据库配置、各层代码实现以及视图展示。
ssm项目整合,简单的用户管理系统
|
4月前
|
XML Java 数据库连接
如何搭建SSM框架、图书商城系统
这是一份详尽的《Spring + SpringMVC + Mybatis 整合指南》,作者耗时良久整理出约五万字的内容,现已经全部笔记公开。此文档详细地介绍了如何搭建与整合SSM框架,具体步骤包括创建Maven项目、添加web骨架、配置pom文件以及整合Spring、SpringMVC和Mybatis等。无论是对初学者还是有一定基础的开发者来说,都是很好的学习资源。此外,作者还提供了项目源码的GitHub链接,方便读者实践。虽然当前主流推荐学习SpringBoot,但了解SSM框架仍然是不可或缺的基础。
65 0
|
5月前
|
SQL Java 应用服务中间件
使用SSM搭建图书商城管理系统(完整过程介绍、售后服务哈哈哈)
这篇文章是关于如何使用SSM框架搭建图书商城管理系统的教程,包括完整过程介绍、常见问题解答和售后服务,提供了项目地址、运行环境配置、效果图展示以及运行代码的步骤。
使用SSM搭建图书商城管理系统(完整过程介绍、售后服务哈哈哈)
|
6月前
|
存储 关系型数据库 测试技术
基于ssm+vue的校园驿站管理系统+(源码+部署说明+演示视频+源码介绍)(2)
基于ssm+vue的校园驿站管理系统+(源码+部署说明+演示视频+源码介绍)
106 1
|
6月前
|
安全 数据挖掘 测试技术
基于SSM+Vue的家居商城系统(源码+部署说明+演示视频)(2)
基于SSM+Vue的家居商城系统(源码+部署说明+演示视频)
87 0
|
6月前
|
Java 关系型数据库 MySQL
基于SSM+Vue的家居商城系统(源码+部署说明+演示视频)(1)
基于SSM+Vue的家居商城系统(源码+部署说明+演示视频)
82 0
|
7月前
|
搜索推荐 JavaScript Java
计算机Java项目|基于SSM的个性化商铺系统
计算机Java项目|基于SSM的个性化商铺系统
|
7月前
|
前端开发 JavaScript Java
计算机Java项目|SSM智能仓储系统
计算机Java项目|SSM智能仓储系统
|
7月前
|
Java 物联网 Maven
基于SSM+layui【爱车汽车租赁管理系统】附源码+论文
基于SSM+layui【爱车汽车租赁管理系统】附源码+论文
103 1
基于SSM+layui【爱车汽车租赁管理系统】附源码+论文