请问这里为什么报错,没有数据显示

请问这里为什么报错,没有数据显示

"C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9\bin\catalina.bat" run
[2019-09-24 11:14:54,353] Artifact sm_web:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE:   "C:\Users\LXH\.IntelliJIdea2019.2\system\tomcat\Unnamed_sm_2"
Using CATALINA_HOME:   "C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9"
Using CATALINA_TMPDIR: "C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk-11.0.2"
Using CLASSPATH:       "C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9\bin\bootstrap.jar;C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9\bin\tomcat-juli.jar"
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.9
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Dec 5 2016 20:18:12 UTC
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.9.0
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk-11.0.2
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           11.0.2+9-LTS
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\LXH\.IntelliJIdea2019.2\system\tomcat\Unnamed_sm_2
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\LXH\.IntelliJIdea2019.2\system\tomcat\Unnamed_sm_2\conf\logging.properties
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=C:\Users\LXH\.IntelliJIdea2019.2\system\tomcat\Unnamed_sm_2\jmxremote.password
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=C:\Users\LXH\.IntelliJIdea2019.2\system\tomcat\Unnamed_sm_2\jmxremote.access
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\LXH\.IntelliJIdea2019.2\system\tomcat\Unnamed_sm_2
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9\temp
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.10 using APR version 1.5.2.
24-Sep-2019 11:14:55.712 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
24-Sep-2019 11:14:55.728 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
24-Sep-2019 11:14:56.369 信息 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.2j  26 Sep 2016)
24-Sep-2019 11:14:56.415 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8088"]
24-Sep-2019 11:14:56.431 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
24-Sep-2019 11:14:56.431 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8010"]
24-Sep-2019 11:14:56.431 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
24-Sep-2019 11:14:56.431 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1072 ms
24-Sep-2019 11:14:56.478 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
24-Sep-2019 11:14:56.478 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.9
24-Sep-2019 11:14:56.494 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8088]
24-Sep-2019 11:14:56.509 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8010]
24-Sep-2019 11:14:56.509 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 78 ms
Connected to server
[2019-09-24 11:14:56,587] Artifact sm_web:war exploded: Artifact is being deployed, please wait...
24-Sep-2019 11:14:58.524 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
24-Sep-2019 11:14:58.884 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [313] milliseconds.
[2019-09-24 11:14:58,930] Artifact sm_web:war exploded: Artifact is deployed successfully
[2019-09-24 11:14:58,930] Artifact sm_web:war exploded: Deploy took 2,343 milliseconds
24-Sep-2019 11:14:59.493 信息 [http-nio-8088-exec-1] org.springframework.context.support.ClassPathXmlApplicationContext.prepareRefresh Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c48c76b: startup date [Tue Sep 24 11:14:59 CST 2019]; root of context hierarchy
24-Sep-2019 11:14:59.633 信息 [http-nio-8088-exec-1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from class path resource [spring.xml]
24-Sep-2019 11:15:00.508 信息 [http-nio-8088-exec-1] org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName Loaded JDBC driver: com.mysql.jdbc.Driver
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.imooc.sm.global.MainContrallServlet.service(MainContrallServlet.java:57)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at com.imooc.sm.global.EncodingFilter.doFilter(EncodingFilter.java:21)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:834)
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.$Proxy16.selectAll(Unknown Source)
	at com.imooc.sm.service.impl.DepartmentServiceImpl.getAll(DepartmentServiceImpl.java:36)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	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.$Proxy17.getAll(Unknown Source)
	at com.imooc.sm.controller.departmentController.list(departmentController.java:20)
	... 30 more
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.imooc.sm.global.MainContrallServlet.service(MainContrallServlet.java:57)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at com.imooc.sm.global.EncodingFilter.doFilter(EncodingFilter.java:21)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:834)
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.$Proxy16.selectAll(Unknown Source)
	at com.imooc.sm.service.impl.DepartmentServiceImpl.getAll(DepartmentServiceImpl.java:36)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	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.$Proxy17.getAll(Unknown Source)
	at com.imooc.sm.controller.departmentController.list(departmentController.java:20)
	... 30 more
24-Sep-2019 11:15:06.506 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9\webapps\manager
24-Sep-2019 11:15:06.568 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\Users\LXH\Desktop\java EE\apache-tomcat-8.5.9\webapps\manager has finished in 62 ms


正在回答 回答被采纳积分+1

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

4回答
芝芝兰兰 2019-09-25 15:07:46

同学你好,查看一下你的sm_web的pom文件中是否有引入sm呢?

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

如果解答了同学的疑问,望采纳~

祝学习愉快~

芝芝兰兰 2019-09-24 16:08:03

同学你好。可以另外写一个单元测试,在sm_web的pom中引入依赖:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${spring.version}</version>
</dependency>

然后在src下创建测试目录test/java,在java文件夹上右击应用为测试根目录:

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

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

在测试类的头部使用 @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("spring.xml")来声明spring位置,然后在这个测试类使用@Autowired注入departmentController,再调用departmentController的list()方法哦~如:

import com.imooc.sm.controller.DepartmentController;
import com.imooc.sm.service.DepartmentService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("spring.xml")
public class TestDepartmentController {
    @Autowired
    DepartmentController departmentController;

    @Test
    public void testMethod(){
        departmentController.list();
    }
}

如果解答了同学的疑问,望采纳~

祝学习愉快~

  • 提问者 慕村4575073 #1
    为什么根据老师的代码,我在sm_web中无法识别到定义在smPOm文件夹的spring版本呢?sm_service可以识别到
    2019-09-25 10:52:57
芝芝兰兰 2019-09-24 14:28:46

同学你好。

1、报错信息是:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.imooc.sm.dao.DepartmentDao.selectAll

MyBatis绑定错误,找不到DepartmentDao.selectAll方法,

可能同学使用的是“.”分割的形式创建的多级目录,可以将这里的对勾取消:

5d81fd7609d6dd8f04720545.jpg

看一下自己的resources文件夹下是不是还是在一起的:

5d81fe5009e5a9b802890073.jpg

而不是:

5d81fe33091443f203100174.jpg

idea在resources中创建多级包的方式就是以“/”分割,而不是以“.”分割。使用“.”创建,idea并不会将其视为多级目录,而是一个名为“com.imooc.sm.dao”的包,自然就不会在编译时将其放入多级目录中。

例如应该使用:

5d81fefb09c634c205830178.jpg

而不是这样创建:

5d81ff24090e9e3905830178.jpg

建议同学修改后再重新点击重新编译试一下

2、空指针是因为测试方式有问题,直接new出的departmentController对象是没有交给Spring管理的。所以无法使用@Autowired注解进行自动注入。此时的departmentService相当于还没有初始化,所以有空指针异常。

另外,类名建议命名规范,首字母要大写。

如果解答了同学的疑问,望采纳~

祝学习愉快~

  • 提问者 慕村4575073 #1
    按照这样更改的话,这个DepartmentController该怎么编写呢
    2019-09-24 14:35:24
提问者 慕村4575073 2019-09-24 11:28:18

在控制器中测试的时候显示空指针异常

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;

    public void list() throws ServletException, IOException {
        List<Department> list = departmentService.getAll();
        for(Department department :list){
            System.out.println(department.getName());
        }
//        request.setAttribute("LIST",list);
//        request.getRequestDispatcher("../department_list.jsp").forward(request,response);
    }

    public static void main(String[] args) throws ServletException, IOException {
    new  departmentController().list();
    }
}
Exception in thread "main" java.lang.NullPointerException
	at com.imooc.sm.controller.departmentController.list(departmentController.java:20)
	at com.imooc.sm.controller.departmentController.main(departmentController.java:29)

Process finished with exit code 1


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

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

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

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

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