SpringBoot应用过程中的报错

案例1
  • R:\Assistant_software\jdk1.8\bin\java.exe ...  [main] DEBUG org.springframework.boot.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/R:/Assistant_software/jdk1.8/jre/lib/charsets.jar, file:/R:/Assistant_software/jdk1.8/jre/lib/deploy.jar, file
  • 原因:yml配置文件中的中文注释引发错误
  • 解决:yml配置文件里的中文注解删了或者改成英文注解就能运行,这是编码的问题,也可将编码改成 UTF-8
 
案例2
  • 全部书写正确,根本找不出错误,但是网页加载错误
  • 原因:applilcation.yml写错,配置信息比如端口,项目名称无法识别
  • 解决:更改为正确的application.yml(真的是一个字符都不能错)
 
案例3
  • Element 'dependency' cannot have character [children], because the type's content type is element-on
  • 原因:先填写了<artifactId>标签的内容,再手写<groupId>
  • 解决:重建一个,先写<groupId>再自动生成<artifactId>标签里面的内容,比如在导入mysql依赖报错
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.38</version>
</dependency>
 
案例4
  • An error happened during template parsing (template: "class path resource [templates/success1.html]"
  • 原因:要么thymeleaf的配置没有完整,要么.html文件有格式错误,这里报错是因为 .html文件中写了一句 <script th:src=""></script> 
  • 解决:要么不用th:src="",要么就在引号里面填内容,删掉,或者补充完整
 
案例5
  • This application has no explicit mapping for /error, so you are seeing this as a fallback.
  • 原因:浏览地址比如/user/register中没有跳转页面,程序事实上已经实现了,只是没有页面
  • 解决:增加或修改跳转页面
 
案例6
  • 使用mybatis的select查找,返回null,但却有个数
  • 原因:字段不匹配,比如entity中User属性是id,但Mysql中User属性是 U_id
  • 解决:统一将实体类中的变量跟Mysql中的一样
 
案例7
  • 导入js失败,thymeleaf配置没问题,th:src语法也没问题
  • 原因:有可能是缓存问题
  • 解决:重启一下IDEA试试
 
案例8
  • 前端输入<input type="Date">,后端无法接收
  • 原因:格式问题
  • 解决:例如按照年/月/日的格式, 加一个注解@DateTimeFormat(pattern = "yyyy-MM-dd")
@PostMapping("/registerUP")
public String registerUP(
        @RequestParam(value = "id", required = false) String id,
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        @RequestParam(value = "birthday", required = false) Date birthday
) {
 
    return "redirect:/user/register";
}

 

 
案例9
  • Data truncation: Incorrect date value: '55567' for column 'P_birthday' at row 1
  • 原因:sql进行insert操作,字段不匹配,sql语句出错了,去排查
  • 解决:sql语句中修改对应字段
 
案例10
  • 使用select查找人数返回为0
  • 原因:select count( #{U_id} ) from user, sql语法错误,统计数量并不需要查找指定U_id,习惯了Mapper的读取变量写法
  • 解决:select count(U_id) from user, 去掉 #{ } 即可

 

备注:

  多看看报错信息,会有收获的,很多bug可以通过控制台知道报错原因,再对应去解决,可以百度,或者搜索别人的博客经验

posted @ 2020-10-24 11:11  a最简单  阅读(565)  评论(0)    收藏  举报