麻烦老师帮我看看,找不到方法
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.imooc.sm.global.DispatcherServlet.service(DispatcherServlet.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.imooc.sm.global.EncodingFilter.doFilter(EncodingFilter.java:19) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NoSuchMethodError: com.imooc.sm.dao.StaffDao.selectById(Ljava/lang/Integer;)Lcom/imooc/sm/entity/Staff; at com.imooc.sm.service.impl.StaffServiceImpl.get(StaffServiceImpl.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy20.get(Unknown Source) at com.imooc.sm.controller.StaffController.detail(StaffController.java:117) ... 30 more
package com.imooc.sm.service.impl; import com.imooc.sm.dao.StaffDao; import com.imooc.sm.entity.Staff; import com.imooc.sm.service.StaffService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; @Service("staffService") public class StaffServiceImpl implements StaffService { @Autowired private StaffDao staffDao; public void add(Staff staff) { staff.setPassword("123456"); staff.setWorkTime(new Date()); staff.setStatus("正常"); staffDao.insert(staff); } public void remove(Integer id) { staffDao.delete(id); } public void edit(Staff staff) { staffDao.update(staff); } public Staff get(Integer id) { System.out.println("1111111111"); return staffDao.selectById(id); } public List<Staff> getAll() { return staffDao.selectAll(); } }
package com.imooc.sm.controller; import com.imooc.sm.entity.Department; import com.imooc.sm.entity.Staff; import com.imooc.sm.service.DepartmentService; import com.imooc.sm.service.StaffService; 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.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @Controller("staffController") public class StaffController { @Autowired private StaffService staffService; @Autowired private DepartmentService departmentService; public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<Staff> list = staffService.getAll(); request.setAttribute("LIST",list); request.getRequestDispatcher("../staff_list.jsp").forward(request,response); } public void toAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<Department> list = departmentService.getAll(); request.setAttribute("DLIST",list); request.getRequestDispatcher("../staff_add.jsp").forward(request,response); } public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String account = request.getParameter("account"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String idNumber = request.getParameter("idNumber"); String info =request.getParameter("info"); Date bornDate=null; try { bornDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("bornDate")); } catch (ParseException e) { e.printStackTrace(); } Integer did = Integer.parseInt(request.getParameter("did")); Staff staff = new Staff(); staff.setInfo(info); staff.setBornDate(bornDate); staff.setIdNumber(idNumber); staff.setDid(did); staff.setAccount(account); staff.setName(name); staff.setSex(sex); /**由于staff是之前数据库中查询出来的,department属性没有修改,只修改了did属性 * 所以,我们把department根据did属性查询出来并设置给staff的department属性*/ Department department = departmentService . get(did); staff.setDepartment (department); //判断一下, 如果当前修改的用户与当前登录的用户是同一个,把修改后的用户放到session 中 // Staff staff1 = (Staff) request. getSession(). getAttribute("USER"); // if(staff1. getId().equals(staff.getId())){ // request.getSession(). setAttribute("USER" ,staff); // } staffService.add(staff); response.sendRedirect("list.do"); } public void toEdit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Integer id = Integer.parseInt(request.getParameter("id")); System.out.println(id); Staff staff = staffService.get(id); System.out.println(staff); request.setAttribute("OBJ",staff); List<Department> list = departmentService.getAll(); request.setAttribute("DLIST",list); request.getRequestDispatcher("../staff_edit.jsp").forward(request,response); } public void edit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Integer id = Integer.parseInt(request.getParameter("id")); String account = request.getParameter("account"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String idNumber = request.getParameter("idNumber"); String info =request.getParameter("info"); Date bornDate=null; try { bornDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("bornDate")); } catch (ParseException e) { e.printStackTrace(); } Integer did = Integer.parseInt(request.getParameter("did")); Staff staff = staffService.get(id); staff.setInfo(info); staff.setBornDate(bornDate); staff.setIdNumber(idNumber); staff.setDid(did); staff.setAccount(account); staff.setName(name); staff.setSex(sex); staffService.edit(staff); response.sendRedirect("list.do"); } public void remove(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Integer id = Integer.parseInt(request.getParameter("id")); staffService.remove(id); response.sendRedirect("list.do"); } public void detail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Integer id = Integer.parseInt(request.getParameter("id")); Staff staff = staffService.get(id); request.setAttribute("OBJ",staff); request.getRequestDispatcher("../staff_detail.jsp").forward(request,response); } }
15
收起
正在回答
2回答
同学你好,检查同学的代码并没有什么问题,建议同学删除target文件,重启项目再试试。
祝:学习愉快~
不停奔跑的小恐龙
2020-01-21 22:39:17
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.imooc.sm.dao.StaffDao"> <resultMap id="resultMap" type="Staff"> <id property="id" column="id" javaType="Integer"/> <result property="account" column="account" javaType="String"/> <result property="password" column="password" javaType="String"/> <result property="status" column="status" javaType="String"/> <result property="did" column="did" javaType="Integer"/> <result property="name" column="name" javaType="String"/> <result property="sex" column="sex" javaType="String"/> <result property="idNumber" column="id_number" javaType="String"/> <result property="workTime" column="work_time" javaType="java.util.Date"/> <result property="leaveTime" column="leave_time" javaType="java.util.Date"/> <result property="bornDate" column="born_date" javaType="java.util.Date"/> <result property="info" column="info" javaType="String"/> <association property="department" column="did" javaType="Department" select="com.imooc.sm.dao.DepartmentDao.selectById" /> </resultMap> <insert id="insert" parameterType="Staff" useGeneratedKeys="true"> insert into staff(account,password,status,did,name,sex,id_number,work_time,leave_time,born_date,info) values(#{account},#{password},#{status},#{did},#{name},#{sex},#{idNumber},#{workTime},#{leaveTime},#{bornDate},#{info}) </insert> <delete id="delete" parameterType="Integer"> delete from staff where id=#{id} </delete> <update id="update" parameterType="Staff"> update staff set account=#{account},password=#{password},status=#{status}, did=#{did},name=#{name},sex=#{sex},id_number=#{idNumber}, work_time=#{workTime},leave_time=#{leaveTime},born_date=#{bornDate},info=#{info} where id=#{id} </update> <select id="selectById" parameterType="Integer" resultMap="resultMap"> select * from staff where id=#{id} </select> <select id="selectAll" resultMap="resultMap"> select * from staff </select> </mapper>
package com.imooc.sm.dao; import com.imooc.sm.entity.Staff; import org.springframework.stereotype.Repository; import java.util.List; @Repository("staffDao") public interface StaffDao { void insert(Staff staff); void delete(Integer id); void update(Staff staff); Staff selectById(Integer id); List<Staff> selectAll(); }
可以获取到前端传来的属性
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星