Java项目:SSM教师师资管理系统

作者主页:源码空间站2022

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

项目介绍

本项目包含管理员与教师两种角色;

管理员角色包含以下功能:

管理员角色登录,教师管理,教师授课管理,审批教师的项目开题,项目详情审批,项目总结审批,公告管理等功能。

教师角色包含以下功能:

教师角色登录,修改个人信息,修改密码,公告列表管理,开题审批管理,项目排名,项目详情审批管理,项目总结管理等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 

5.数据库:MySql 5.7/8.0版本均可;

6.是否Maven项目:是;

技术栈

1. 后端:Spring+SpringMVC+Mybatis

2. 前端:Jsp+CSS+JavaScript+jQuery+bootstrap

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;

3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;

4. 运行项目,输入localhost:8080/ 登录

运行截图

管理员角色

Java项目:SSM教师师资管理系统_第1张图片

Java项目:SSM教师师资管理系统_第2张图片

Java项目:SSM教师师资管理系统_第3张图片

Java项目:SSM教师师资管理系统_第4张图片

Java项目:SSM教师师资管理系统_第5张图片

Java项目:SSM教师师资管理系统_第6张图片教师角色 

Java项目:SSM教师师资管理系统_第7张图片

Java项目:SSM教师师资管理系统_第8张图片

Java项目:SSM教师师资管理系统_第9张图片

Java项目:SSM教师师资管理系统_第10张图片

Java项目:SSM教师师资管理系统_第11张图片

Java项目:SSM教师师资管理系统_第12张图片

相关代码

登录模块

package com.kewen.teacher.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.kewen.teacher.base.BaseController;
import com.kewen.teacher.po.Manage;
import com.kewen.teacher.po.Teacher;
import com.kewen.teacher.po.Teacherclass;
import com.kewen.teacher.service.ManageService;
import com.kewen.teacher.service.TeacherService;

@Controller
@RequestMapping("/login")
public class LoginController  extends BaseController{
	
	@Autowired
	private ManageService manageService;
	
	@Autowired
	private TeacherService teacherService;
	
	/**
	 * 跳转登陆
	 * @return
	 */
	@RequestMapping("/login")
	public String login(){
		return "login/mLogin";
	}
	
	
	@RequestMapping("/mtuichu")
	public String mtuichu(HttpServletRequest request){
		//request.getSession().invalidate();
		return "login/mLogin";
	}
	@RequestMapping("/welcome")
	private String welcome(){
		return "login/welcome";
	}
	
	@RequestMapping("/toLogin")
	public String toLogin(Manage manage, Integer type,HttpServletRequest request, HttpServletResponse response){
		
		if (type == null){
			return "redirect:/login/mtuichu";	
		}
		
		if (type == 1){
			Manage byEntity = manageService.getByEntity(manage);
			if(byEntity == null){
				return "redirect:/login/mtuichu";	
			}else{
				request.getSession().setAttribute("role", 1);
				request.getSession().setAttribute("username", byEntity.getUserName());
				request.getSession().setAttribute("userId", byEntity.getId());
			}
		}
		if (type == 2){
			Teacher t = new Teacher();
			t.setPassword(manage.getPassWord());
			t.setUsername(manage.getUserName());
			t.setIsDelete(0);
			Teacher byEntity = teacherService.getByEntity(t);
			if(byEntity == null){
				return "redirect:/login/mtuichu";	
			}else{
				request.getSession().setAttribute("role", 2);
				request.getSession().setAttribute("username", byEntity.getUsername());
				request.getSession().setAttribute("userId", byEntity.getId());
			}
		}
		
		
		return "login/mIndex";
	}
	
	/**
	 * 退出
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/tuichu")
	public String tuichu( HttpServletRequest request, HttpServletResponse response){
		HttpSession session = request.getSession();
		session.invalidate();
		return "login/login";
	}

	@RequestMapping("/head")
	private String head(){
		return "inc/head";
	}
	
	@RequestMapping("/left")
	private String left(){
		return "inc/left";
	}
	
	
	@RequestMapping(value = "/update")
	public String update(Integer id,Model model,HttpServletRequest request) {
		
		Object attribute = request.getSession().getAttribute("userId");
		
		if (attribute == null){
			return "redirect:/login/mtuichu";	
		}
		
		Integer userId = Integer.valueOf(attribute.toString());
		Teacher byId = teacherService.getById(userId);
		model.addAttribute("obj",byId);
		return "login/update";
	}
	

	@RequestMapping(value = "/toUpdate")
	public String toUpdate(Integer id,String phone,Model model,HttpServletRequest request) {
		
		Object attribute = request.getSession().getAttribute("userId");
		
		if (attribute == null){
			return "redirect:/login/mtuichu";	
		}
		
		Integer userId = Integer.valueOf(attribute.toString());
		Teacher byId = teacherService.getById(userId);
		byId.setPhone(phone);
		teacherService.updateById(byId);
		model.addAttribute("obj",byId);
		return "login/update";
	}
	
	@RequestMapping(value = "/pass")
	public String pass(Integer id,Model model,HttpServletRequest request) {
		
		Object attribute = request.getSession().getAttribute("userId");
		
		if (attribute == null){
			return "redirect:/login/mtuichu";	
		}
		
		Integer userId = Integer.valueOf(attribute.toString());
		Teacher byId = teacherService.getById(userId);
		model.addAttribute("obj",byId);
		return "login/pass";
	}
	
	@RequestMapping("/upass")
	@ResponseBody
	public String upass(HttpServletRequest request,String password){
      Object attribute = request.getSession().getAttribute("userId");
      JSONObject j = new  JSONObject();
	   	if (attribute == null){
	   		j.put("res", 0);
	   		return j.toString();
		}
			Integer userId = Integer.valueOf(attribute.toString());
			Teacher byId = teacherService.getById(userId);
			byId.setPassword(password);
			teacherService.updateById(byId);
			j.put("res", 1);
			return j.toString();
			
	}
	
}

管理模块

package com.kewen.teacher.controller;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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 org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.alibaba.fastjson.JSONObject;
import com.kewen.teacher.base.BaseController;
import com.kewen.teacher.mapper.*;
import com.kewen.teacher.po.*;
import com.kewen.teacher.service.*;
import com.kewen.teacher.utils.Pager;

import java.util.*;



@Controller
@RequestMapping("/manage")
public class ManageController extends BaseController {
	
	
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private ManageService manageService;
	
	// --------------------------------------- 华丽分割线 ------------------------------
	
	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listAll")
	public String listAll(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
		List listAll = manageService.listAll();
		model.addAttribute("list", listAll);
		return "manage/manage";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntity")
	public String listByEntity(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
		List listAll = manageService.listAllByEntity(manage);
		model.addAttribute("list", listAll);
		return "manage/manage";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMap")
	public String listByMap(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map params = new HashMap();
	        if(!isEmpty(manage.getUserName())){
	        	params.put("userName", manage.getUserName());
			}
	        if(!isEmpty(manage.getPassWord())){
	        	params.put("passWord", manage.getPassWord());
			}
	        if(!isEmpty(manage.getRealName())){
	        	params.put("realName", manage.getRealName());
			}
	    List listAll = manageService.listByMap(params);
		model.addAttribute("list", listAll);
		return "manage/manage";
	}
	
	
	/*********************************查询列表【分页】***********************************************/
	
	
	
	/**
	 * 分页查询 返回list对象(通过对象)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByObj")
	public String findByObj(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager pagers = manageService.findByEntity(manage);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", manage);
		return "manage/manage";
	}
	
	/**
	 * 分页查询 返回list对象(通过对By Sql)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findBySql")
	public String findBySql(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		String sql = "SELECT * FROM manage WHERE 1=1 ";
        if(!isEmpty(manage.getUserName())){
        	sql += " and userName like '%"+manage.getUserName()+"%'";
		}
        if(!isEmpty(manage.getPassWord())){
        	sql += " and passWord like '%"+manage.getPassWord()+"%'";
		}
        if(!isEmpty(manage.getRealName())){
        	sql += " and realName like '%"+manage.getRealName()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		Pager pagers = manageService.findBySqlRerturnEntity(sql);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", manage);
		return "manage/manage";
	}
	
	
	/**
	 * 分页查询 返回list对象(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMap")
	public String findByMap(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
		//通过map查询
		Map params = new HashMap();
        if(!isEmpty(manage.getUserName())){
        	params.put("userName", manage.getUserName());
		}
        if(!isEmpty(manage.getPassWord())){
        	params.put("passWord", manage.getPassWord());
		}
        if(!isEmpty(manage.getRealName())){
        	params.put("realName", manage.getRealName());
		}
		//分页查询
		Pager pagers = manageService.findByMap(params);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", manage);
		return "manage/manage";
	}
	
	/**********************************【增删改】******************************************************/
	
	/**
	 * 跳至添加页面
	 * @return
	 */
	@RequestMapping(value = "/add")
	public String add() {
		return "manage/add";
	}

	/**
	 * 跳至详情页面
	 * @return
	 */
	@RequestMapping(value = "/view")
	public String view(Integer id,Model model) {
		Manage obj = manageService.load(id);
		model.addAttribute("obj",obj);
		return "manage/view";
	}
	
	/**
	 * 添加执行
	 * @return
	 */
	@RequestMapping(value = "/exAdd")
	public String exAdd(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
		manageService.insert(manage);
		return "redirect:/manage/findBySql.action";
	}
	
	
	/**
	 * 跳至修改页面
	 * @return
	 */
	@RequestMapping(value = "/update")
	public String update(Integer id,Model model) {
		Manage obj = manageService.load(id);
		model.addAttribute("obj",obj);
		return "manage/update";
	}
	
	/**
	 * 添加修改
	 * @return
	 */
	@RequestMapping(value = "/exUpdate")
	public String exUpdate(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		manageService.updateById(manage);
		//2.通过主键id修改
		//manageService.updateById(manage);
		return "redirect:/manage/findBySql.action";
	}
	
	/**
	 * 删除通过主键
	 * @return
	 */
	@RequestMapping(value = "/delete")
	public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
		///1.通过主键删除
		manageService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		manageService.deleteByEntity(manage);
//		//3.通过参数删除
//     //通过map查询
//		Map params = new HashMap();
//		
//        if(!isEmpty(manage.getUserName())){
//        	params.put("userName", manage.getUserName());
//		}
//       
//        if(!isEmpty(manage.getPassWord())){
//        	params.put("passWord", manage.getPassWord());
//		}
//       
//        if(!isEmpty(manage.getRealName())){
//        	params.put("realName", manage.getRealName());
//		}
//       
//		manageService.deleteByMap(params);
//		//4.状态删除
//		Manage load = manageService.getById(manage.getId())
//		load.setIsDelete(1);
//		manageService.update(load);
		//5.状态删除
		//Manage load = manageService.load(id);
		//load.setIsDelete(1);
		//manageService.update(load);
		return "redirect:/manage/findBySql.action";
	}
	
	// --------------------------------------- 华丽分割线 ------------------------------
	// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------

	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
	@ResponseBody
	public String listAllJson(Manage manage, HttpServletRequest request, HttpServletResponse response){
		List listAll = manageService.listAll();
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", manage);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByEntityJson(Manage manage,  HttpServletRequest request, HttpServletResponse response){
		List listAll = manageService.listAllByEntity(manage);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", manage);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByMapJson(Manage manage,HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map params = new HashMap();
	        if(!isEmpty(manage.getUserName())){
	        	params.put("userName", manage.getUserName());
			}
	        if(!isEmpty(manage.getPassWord())){
	        	params.put("passWord", manage.getPassWord());
			}
	        if(!isEmpty(manage.getRealName())){
	        	params.put("realName", manage.getRealName());
			}
	    List listAll = manageService.listByMap(params);
	    JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", manage);
		return jsonObject.toString();
	}
	
	
	/**
	 * 分页查询 返回list json(通过对象)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
	@ResponseBody
	public String findByObjByEntityJson(Manage manage, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager pagers = manageService.findByEntity(manage);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", manage);
		return jsonObject.toString();
	}
	
	  
	/**
	 * 分页查询 返回list json(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMapJson",  method = RequestMethod.POST)
	@ResponseBody
	public String findByMapJson(Manage manage,HttpServletRequest request, HttpServletResponse response) {
		//通过map查询
		Map params = new HashMap();
        if(!isEmpty(manage.getUserName())){
        	params.put("userName", manage.getUserName());
		}
        if(!isEmpty(manage.getPassWord())){
        	params.put("passWord", manage.getPassWord());
		}
        if(!isEmpty(manage.getRealName())){
        	params.put("realName", manage.getRealName());
		}
		//分页查询
		Pager pagers = manageService.findByMap(params);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", manage);
		return jsonObject.toString();
	}
	
	
	/**
	 * ajax 添加
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
	@ResponseBody
	public String exAddJson(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
		manageService.insert(manage);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "添加成功");
		return jsonObject.toString();
	}
	

	/**
	 * ajax 修改
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
	@ResponseBody
	public String exUpdateJson(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		manageService.updateById(manage);
		//2.通过主键id修改
		//manageService.updateById(manage);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "修改成功");
		return jsonObject.toString();
	}

	/**
	 * ajax 删除
	 * @return
	 */
	@RequestMapping(value = "/delete.json", method = RequestMethod.POST)
	@ResponseBody
	public String exDeleteJson(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
		///1.通过主键删除
		manageService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		manageService.deleteByEntity(manage);
//		//3.通过参数删除
//        //通过map查询
//		Map params = new HashMap();
//		
//        if(!isEmpty(manage.getUserName())){
//        	params.put("userName", manage.getUserName());
//		}
//       
//        if(!isEmpty(manage.getPassWord())){
//        	params.put("passWord", manage.getPassWord());
//		}
//       
//        if(!isEmpty(manage.getRealName())){
//        	params.put("realName", manage.getRealName());
//		}
//       
//		manageService.deleteByMap(params);
//		//4.状态删除
//		Manage load = manageService.getById(manage.getId())
//		load.setIsDelete(1);
//		manageService.updateById(load);
		//5.状态删除
		//Manage load = manageService.load(id);
		//load.setIsDelete(1);
		//manageService.updateById(load);
		JSONObject jsonObject = new JSONObject();
		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[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 "";
	}
 // --------------------------------------- 华丽分割线 ------------------------------
	
	
}

教师模块

package com.kewen.teacher.controller;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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 org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.alibaba.fastjson.JSONObject;
import com.kewen.teacher.base.BaseController;
import com.kewen.teacher.po.*;
import com.kewen.teacher.utils.Pager;
import java.util.*;

import com.kewen.teacher.po.*;
import com.kewen.teacher.mapper.*;
import com.kewen.teacher.service.*;

/**
 * @ClassName:  
 * @Description: 
 * @author  - - admin
 * @date - 2018年10月23日 19时51分27秒
 */


@Controller
@RequestMapping("/teacher")
public class TeacherController extends BaseController {
	
	
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private TeacherService teacherService;
	
	// --------------------------------------- 华丽分割线 ------------------------------
	
	/**
	 * 分页查询 返回list对象(通过对By Sql)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findBySql")
	public String findBySql(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		String sql = "SELECT * FROM teacher WHERE isDelete = 0 ";
        if(!isEmpty(teacher.getUsername())){
        	sql += " and username like '%"+teacher.getUsername()+"%'";
		}
        if(!isEmpty(teacher.getSex())){
        	sql += " and sex like '%"+teacher.getSex()+"%'";
		}
        if(!isEmpty(teacher.getPassword())){
        	sql += " and password like '%"+teacher.getPassword()+"%'";
		}
        if(!isEmpty(teacher.getXw())){
        	sql += " and xw like '%"+teacher.getXw()+"%'";
		}
        if(!isEmpty(teacher.getPhone())){
        	sql += " and phone like '%"+teacher.getPhone()+"%'";
		}
        if(!isEmpty(teacher.getIsDelete())){
        	sql += " and isDelete like '%"+teacher.getIsDelete()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		Pager pagers = teacherService.findBySqlRerturnEntity(sql);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", teacher);
		return "teacher/teacher";
	}
	
	
	/**
	 * 分页查询 返回list对象(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMap")
	public String findByMap(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
		//通过map查询
		Map params = new HashMap();
        if(!isEmpty(teacher.getUsername())){
        	params.put("username", teacher.getUsername());
		}
        if(!isEmpty(teacher.getSex())){
        	params.put("sex", teacher.getSex());
		}
        if(!isEmpty(teacher.getPassword())){
        	params.put("password", teacher.getPassword());
		}
        if(!isEmpty(teacher.getXw())){
        	params.put("xw", teacher.getXw());
		}
        if(!isEmpty(teacher.getPhone())){
        	params.put("phone", teacher.getPhone());
		}
        if(!isEmpty(teacher.getIsDelete())){
        	params.put("isDelete", teacher.getIsDelete());
		}
		//分页查询
		Pager pagers = teacherService.findByMap(params);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", teacher);
		return "teacher/teacher";
	}
	
	/**********************************【增删改】******************************************************/
	
	/**
	 * 跳至添加页面
	 * @return
	 */
	@RequestMapping(value = "/add")
	public String add() {
		return "teacher/add";
	}

	/**
	 * 跳至详情页面
	 * @return
	 */
	@RequestMapping(value = "/view")
	public String view(Integer id,Model model) {
		Teacher obj = teacherService.load(id);
		model.addAttribute("obj",obj);
		return "teacher/view";
	}
	
	/**
	 * 添加执行
	 * @return
	 */
	@RequestMapping(value = "/exAdd")
	public String exAdd(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
		teacher.setIsDelete(0);
		teacher.setPassword("111111");
		teacherService.insert(teacher);
		return "redirect:/teacher/findBySql.action";
	}
	
	
	/**
	 * 跳至修改页面
	 * @return
	 */
	@RequestMapping(value = "/update")
	public String update(Integer id,Model model) {
		Teacher obj = teacherService.load(id);
		model.addAttribute("obj",obj);
		return "teacher/update";
	}
	
	/**
	 * 添加修改
	 * @return
	 */
	@RequestMapping(value = "/exUpdate")
	public String exUpdate(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
		teacherService.updateById(teacher);
		return "redirect:/teacher/findBySql.action";
	}
	
	/**
	 * 删除通过主键
	 * @return
	 */
	@RequestMapping(value = "/delete")
	public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
		Teacher load = teacherService.load(id);
		load.setIsDelete(1);
		teacherService.updateById(load);
		return "redirect:/teacher/findBySql.action";
	}
	
}

如果也想学习本系统,下面领取。关注并回复:097ssm 

你可能感兴趣的:(ssm,java,开发语言)