报了个错????先是报了404,然后就空白页了
department/list.do
departmentController
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:51)
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:23)
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:543)
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:609)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
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: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.imooc.sm.dao.DepartmentDao.selectAll
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:225)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy17.selectAll(Unknown Source)
at com.imooc.sm.service.impl.DepartmentService.getAll(DepartmentService.java:34)
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.$Proxy19.getAll(Unknown Source)
at com.imooc.sm.controller.DepartmentController.list(DepartmentController.java:20)
... 30 more
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); } }
package com.imooc.sm.global;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class DispatcherServlet extends GenericServlet {
private ApplicationContext context;
public void init() throws ServletException {
super.init();
context = new ClassPathXmlApplicationContext("spring.xml");
}
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
/*
staff/add.do login.do
staffController
public void add(HttpServletRequest request, HttpServletResponse response){}
*
*/
String path = request.getServletPath().substring(1);
System.out.println(path);
String beanName = null;
String methodName = null;
int index = path.indexOf('/');
if (index != -1) {
beanName = path.substring(0, index) + "Controller";
methodName = path.substring(index + 1, path.indexOf(".do"));
} else {
beanName = "selfController";
methodName = path.substring(0, path.indexOf(".do"));
}
System.out.println(beanName);
Object obj = context.getBean(beanName);
try {
Method method = obj.getClass().getMethod(methodName,HttpServletRequest.class,HttpServletResponse.class);
method.invoke(obj,request,response);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
package com.imooc.sm.global;
import javax.servlet.*;
import java.io.IOException;
/**
* 编码过滤器
*/
public class EncodingFilter implements Filter {
//设置字符级
private String encoding;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
if(filterConfig.getInitParameter("Encoding")==null){
encoding = "UTF-8";
}
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
servletRequest.setCharacterEncoding(encoding);
servletResponse.setCharacterEncoding(encoding);
filterChain.doFilter(servletRequest,servletResponse);
}
@Override
public void destroy() {
encoding=null;
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>部门列表</title> <link rel="stylesheet" type="text/css" href="../css/reset.css"/> <link rel="stylesheet" type="text/css" href="../css/common.css"/> <link rel="stylesheet" type="text/css" href="../css/thems.css"> <script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script> <script type="text/javascript"> $(function(){ //自适应屏幕宽度 window.onresize=function(){ location=location }; var main_h = $(window).height(); $('.hy_list').css('height',main_h-45+'px'); var search_w = $(window).width()-40; $('.search').css('width',search_w+'px'); //$('.list_hy').css('width',search_w+'px'); }); </script> <!--框架高度设置--> </head> <body onLoad="Resize();"> <div id="right_ctn"> <div class="right_m"> <div class="hy_list"> <div class="box_t"> <span class="name">部门列表</span> </div> <div class="space_hx"> </div> <!--列表--> <table cellpadding="0" cellspacing="0" class="list_hy"> <tr> <th scope="col">名称</th> <th scope="col">地址</th> <th scope="col">操作</th> </tr> <c:forEach items="${LIST}" var="dep"> <tr> <td>${dep.name}</td> <td>${dep.address}</td> <td> <a href="toEdit.do?id=${dep.id}" class="btn">编辑</a> <a href="remove.do?id=${dep.id}" class="btn">删除</a> </td> </tr> </c:forEach> </table> <!--列表--> <!--右边底部--> <div class="r_foot"> <div class="r_foot_m"> <a href="toAdd.do" class="btn">添加</a> </div> </div> <!--右边底部--> </div> <!--会议列表--> </div> </div> </body> </html>
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--spring整合mybatis--> <!--数据源--> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=UTF-8"></property> <property name="username" value="root"></property> <property name="password" value="123456"></property> </bean> <!--session工厂--> <bean id="sqlSessionFactor" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="typeAliasesPackage" value="com.imooc.sm.entity"></property> </bean> <!--持久化对象--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.imooc.sm.dao"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactor"></property> </bean> <!--声明事务--> <!--事务管理器--> <bean id="transcationManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!--声明通知--> <tx:advice id="txAdivice" transaction-manager="transcationManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="search*" read-only="true"/> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <!--植入--> <aop:config> <aop:pointcut id="txPointcut" expression="execution(* com.imooc.sm.service.*.*(..))"/> <aop:advisor advice-ref="txAdivice" pointcut-ref="txPointcut"/> </aop:config> <!----> <context:component-scan base-package="com.imooc.sm"/> <aop:aspectj-autoproxy/> </beans>
<?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.DepartmentDao"> <resultMap id="resultMap" type="Department"> <id property="id" javaType="Integer" column="id"/> <result property="name" column="name" javaType="String"/> <result property="address" column="address" javaType="String"/> </resultMap> <insert id="insert" parameterType="Department" useGeneratedKeys="true"> insert into department(name,address) values(#{name},#{address}) </insert> <delete id="delete" parameterType="Integer"> delete form department where id=#{id} </delete> <update id="update" parameterType="Department"> update department set name=#{name},address=#{adress} where id=#{id} </update> <select id="selectById" parameterType="Integer" resultMap="resultMap"> select * from department where id = #{id} </select> <select id="selectAll" resultMap="resultMap"> select * from department </select> </mapper>
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星