SpringBoot项目分页获取数据 java.lang.NullPointerException: null

背景:没学过前端,现在需求写个网页项目,然后突击学习了一下。测试连接数据库已经可以连接,test时数据断点也看到都是正确的,但是在尝试将数据返回前台时发生了如下错误,麻烦各位有经验的指点一下,具体错误如下:

Controller如下图:
img

运行报错:

img

后台报错截图:

img

img
2021-08-30 17:13:00.064 ERROR 11784 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

2021-08-30 17:13:00.329 ERROR 11784 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template [favicon.ico], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [favicon.ico], template might not exist or might not be accessible by any of the configured Template Resolvers

Impl源码:

img

前端html代码:

img

尝试将 “ return userListService.findData(page, limit);”的 page手动赋值1000,limit赋值20:

img

重新运行后发现不报错,但是JSON数据为空:
img

vo写了个toString:

img

后台发现赋值没成功,全部为空:
img

1、对于 page,limit 手动赋值可以执行,是不是前端数据没有传到后台,输出到控制台看有没有
2、对于数据为空,看分页查询有没有拿到数据,xml里查询语句写得是否正确或者querywrapper条件是否正确

那你针对后台为空进行分析。
通过debug调试的方式,跟一下报错的地方,针对性解决。

你的limit和page写死了怎么可以呢?要是修改当前页和一页多少条怎么办?
他只是想让你在参数里面加一个默认值而已,既然你不给他传参就应有个默认值才对呀,例如
xxxx(@RequestParam(defaultValue = "100") Integer page,@RequestParam(defaultValue = "20") Integer limit)
浏览器如果不给他参数,就默认page=100,limit=20


看样子你使用了lombok插件,不然你不可能不写get set方法,以及有参无参构造,和toString
你给的截图只是你数据实体类的,但是你却没有给另一个实体类的截图,你有没有给他进行get set toString方法,那个实体类我猜你是用来改变数据输出格式的,让它和前端的UI框架接收数据保持一致(Layui

问题已解决:
1、首先是Page和Limit值没有前台传递到后台,这个原先有猜测,但是不确定。
2、手动赋值,运行不报错,但是JSON为空,vo没有获取数据库参数,而是new ArrayList的:

谢谢各位的解答!果然闭门造车并不可取,一交流瞬间恍然大悟。