报错完整信息:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
出错原因可能有两个:
1.Service层实现类未添加注解@Autowired
@Autowired的作用是自动注入依赖的Bean
@Service
public class SelectService {
@Autowired //自动注入依赖的bean
SelectMapper selectMapper;
public yuezixi[] Sel(...) {
return selectMapper.Sel(...);
}
}
老哥!别叉网页!!我知道你加了注解还报错!!!
来都来了,不妨看看这个...
2.controller层引入service错误;
在xxxContronller文件主函数中加入下面的函数:
public class UpdateController {
@Autowired
private UserService userService;
private UpdateService updateService;
public UpdateController(UserService userService, UpdateService updateService) {
this.userService = userService;
this.updateService = updateService;
}
}
(祝好运,嘻嘻!解决了可否给我个赞)
鬼知道,我解决完这个问题之后又出现了新的问题...
如果你在做springboot+mysql 对数据库的增删查改...
记住insert、update、delete等sql语句执行成功后的返回值是一个非0的整数!!
嗯!整数!别搞啥boolean!

(网图,侵删)
SpringBoot服务层NullPointerException解决
本文解析了在SpringBoot项目中遇到的NullPointerException异常,主要源于Service层实现类未正确使用@Autowired注解,或Controller层引入Service层时出现错误。文章提供了具体的代码示例,帮助读者理解如何正确使用注解及如何在Controller层中正确引入Service。
2万+

被折叠的 条评论
为什么被折叠?



