bean named 'departmentController' is defined
DepartmentController.java
package com.imooc.sm.controller;
import com.imooc.sm.entity.Department;
import com.imooc.sm.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@Controller("departmentController")
public class DepartmentController {
@Autowired
private DepartmentService departmentService;
// /department/list.do /department_list.jsp
public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Department > list = departmentService.getAll();
request.setAttribute("LIST",list);
request.getRequestDispatcher("../department_list.jsp").forward(request,response);
}
public void toAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("../department_add.jsp").forward(request,response);
}
public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
String address = request.getParameter("address");
Department department = new Department();
department.setName(name);
department.setAddress(address);
departmentService.add(department);
response.sendRedirect("list.do");
}
public void toEdit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Integer id = Integer.parseInt(request.getParameter("id"));
Department department = departmentService.get(id);
request.setAttribute("OBJ",department);
request.getRequestDispatcher("../department_edit.jsp").forward(request,response);
}
public void edit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Integer id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String address = request.getParameter("address");
Department department = new Department();
department.setId(id);
department.setName(name);
department.setAddress(address);
departmentService.edit(department);
response.sendRedirect("list.do");
}
public void remove(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Integer id = Integer.parseInt(request.getParameter("id"));
departmentService.remove(id);
response.sendRedirect("list.do");
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星