bean named 'departmentController' is defined

bean named 'departmentController' is defined

http://img1.sycdn.imooc.com//climg/5c9c95700001896520760884.jpg


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

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕阿莹 2019-03-28 19:20:19

请问同学再配置文件中,是否有扫描这个包呢?

http://img1.sycdn.imooc.com//climg/5c9cad69000197f808550880.jpg

在web模块在pom文件中依赖了service模块的情况下,web层的DispatcherServlet中引用了这个spring.xml,

http://img1.sycdn.imooc.com//climg/5c9cada5000172af08040282.jpg

同学有没有配置这些呢?

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
SSM主流框架入门与综合项目实战2018版
  • 参与学习           人
  • 提交作业       205    份
  • 解答问题       4317    个

Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师