Whitelabel Error Page

原文链接:Whitelabel Error Page – 每天进步一点点 (longkui.site)

某天创建一个springboot项目练练手,访问接口的时候开始报错:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Dec 29 11:01:11 CST 2022
There was an unexpected error (type=Internal Server Error, status=500).

而且这个报错调试了一下,能进后台断点,只是返回的时候开始报错:

然后百度了很多解决方法,最终解决了这个问题,这篇文章简单总结一下出现这个问题的原因和解决方法。

注意1:页面上显示这个这个报错,原因不唯一,很多方面的原因都可能造成这个问题,我只记录了我实际遇到的。

注意2:这个报错是500,不是“There was an unexpected error (type=Not Found, status=404)”如果是404,请先检查一下启动类的位置对不对。

原因1:注解问题

有的时候写代码会忘了某些注解,比如@ResponseBody,这个时候可能控制台一般会报错:

Exception processing template “students/getList”: Error resolving template [students/getList], template might not exist or might not be accessible by any of the configured Template Resolvers

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

可以参考下面这篇文章解决:

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

原因2:数据格式问题

控制台会报错类似下面:

Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: java.time.LocalDateTime cannot be cast to java.lang.String; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.time.LocalDateTime cannot be cast to java.lang.String (through reference chain: java.util.ArrayList[0]->java.util.HashMap[“update_time”])]

可以参考下面这篇文章进行解决:

Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON:

原因3:xml写错

这个主要是xml文件写错了,一般控制台会给出比较明显的提示,比如下面这样:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '})' at line 3
### The error may exist in file [D:\项目\springboot\app\target\classes\mappers\StudentsMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: INSERT INTO `students` (`stu_name`, `stu_sex`, `class_id`, `age`)         VALUES         ( ?, ?, ?, {age});
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '})' at line 3
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '})' at line 3] with root cause

很明显,下面这个地方写错了,要加上#变成 #{age}才行。

 

posted on   longkui  阅读(274)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示