为什么我这边打开页面是空白的

来源:4-5 员工管理实现-界面

weixin_慕神6348411

2019-03-29 10:39:45

http://img.mukewang.com/climg/5c9d852b000112df24581336.jpg


发现报警是


at java.base/java.lang.Thread.run(Thread.java:834)

Caused by: java.lang.NullPointerException

at com.imooc.sm.service.impl.StaffServiceImpl.getAll(StaffServiceImpl.java:41)

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.$Proxy18.getAll(Unknown Source)

at com.imooc.sm.controller.StaffController.list(StaffController.java:27)

... 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) {
       return staffDao.selectById(id);
   }

   public List<Staff> getAll() {
       return staffDao.selectAll();
   }
}

写回答

1回答

好帮手慕阿莹

2019-03-29

同学的代码是报了空指针异常,空指针异常,既有值为null的对象调用方法或属性导致的

根据报错信息猜测是return staffDao.selectAll();这一行代码报错了

也就是staffDao为null,staffDao注入失败。

建议同学看一下staffDao 类上是否有写交给spring管理的注解呢?如果没有,请添加

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

0

0 学习 · 4317 问题

查看课程