java的常见错误

spring mvc错误

错误1

2021-06-15 19:35:07.791 ERROR 12336 --- [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 com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '857' for key 'PRIMARY'] with root cause
错误原因:是因为数据库的表设置了主键自增; 后端向数据库中存入了 相同的重复的数据;

错误2

Tue Jun 15 19:41:52 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

错误的译文

不建议在没有服务器身份验证的情况下建立SSL连接。MySQL 5.5.45+、5.6.26+和5.7.6+要求如果没有设置显式选项,则默认需要建立SSL连接。为了符合未使用SSL的现有应用程序,verifyServerCertificate属性被设置为false'。您需要通过设置useSSL=false显式禁用SSL,或者设置useSSL= true并为服务器证书验证提供信任库。

在后台代码中加上&useSSL=false即可

前端(网页)报的异常:

404异常:前端或网页找不到后端的资源(类/方法)

400异常:前端传入的参数类型与后端的参数类型不匹配

500异常:后端的代码写错了

在前后端传参时 

如果在前后端传参数是输入了参数却返回null , 则说明属性的名字(id,name等)写错了

前端错误原因

Cannot POST /qianduan/ming.html

正确的代码为:

空指针异常

null不能够调用变量,方法等 ;异常原因 : 所以调用方法或变量的值null ; 

2):错误

在文件中或者注入时的路径写错了

3):在springboot和mybatis整合的错误

在测试之后包空指针振错误且字代码写的完全正确 的前提下

 错误原因:在测试类中的@test注解的包导错了

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.jt.test.UserTest': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.jt.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 

org.springframework.beans.factory。创建名为“com.jt.test”的bean时出错。UserTest':通过字段'userMapper'表达的不满足的依赖;嵌套异常是org.springframework。bean。工厂。NoSuchBeanDefinitionException:没有类型为'com. js .mapper '的合格bean。UserMapper可用:预计至少有1个bean符合自动装配候选。依赖注释:{@org。springframework。豆子.factory。注释。Autowired (required-true)}

错误原因没有没有加下面的注解:

@MapperScan("com.jt.mapper")

axios的 错误

属性或方法“deletelUserById”没有在实例上定义,而是在渲染时被引用。通过初始化该属性,确保该属性是反应性的,无论是在data选项中,还是在基于类的组件中。见:https://vueis.org/2/guide/reactivity.html Declaring-Reactive-Preperties。(在<根>)-[Vue warn]: Error in v-on handler: "TypeError: deleteUserById is not a function"(在<根>)-TypeError: deleteUserById不是函数eval at createFunction (yue.js:11649), <anonymous>: 3:566) at invokelithErrorHandling (yue.js:1863)在HTMLButtonElement。调用程序(vue.is: 2188)在HTMLButtonElement.original。_wrapper (yue.js: 7547)

方法没有写在methods里

mybatisplus的错误

错误:在编辑serviceImpl层 使用return返回数据的时候会报错,

错误原因 :需要该项目的user需要com.jt.user实际orgin.appcher.user,是在mapper继承basemapper泛型里 的user引错了,

改错 : 只需要引入该项目的包里的 user

且在启动springboot还会报这样的错误

**

### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM user' at line 1
### The error may exist in com/jt/mapper/UserMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT   FROM user
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM user' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM user' at line 1] with root cause

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM user' at line 1
 

**

错误原因

 错误原因是在启动类里没有加

@MapperScan("com.jt.mapper")这个注解没有加或者这个注解括号里的路径写错了
改错:要么加上这个注解  或者将这个注解的路径写对(注意这里的路径是mapper的路径)

在引入别人的新项目的时候报错

在idea中创建一个新工程,则需要配置新的 maven(在这里只需将之前配好的路径引入到idea中即可)和jdk , 如果pom.xml文件报错那么点击maven的clean和install即可 , 

如果将上一步全部配置好好报错(这里 的错误是所有注解 和一些API 的方法都报错), 错误原因是没有架子啊依赖项 ,  改错::只需放到一个注解上进行添加依赖即可;所有的报错消失(在这里进行多添加一些依赖项) ; 

mybatis的错误

 错误:在编辑serviceImpl层 使用return返回数据的时候会报错,错误原因需要该项目的user需要com.jt.user实际orgin.appcher.user,是在mapper继承basemapper泛型里 的user引错了,只需要引入该项目的包里的 user

如果pom.xml出现像下面图片的情况

那么选中pom右键点击Add as Maven Project

请求类型路径写错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Invalid mapping on handler class [com.cy.ProviderApplication$ProviderController]: public java.lang.String com.cy.ProviderApplication$ProviderController.dogetlevel()

原因

将dolevel的请求类型的注解路径写错了;

改错

将@GetMapping("${provider/doGetLogLevel}")改为@GetMapping("provider/doGetLogLevel")

有下面的错误 

如果代码都对但 @Override报错那么就要改位下面的情况

前端错误

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template [success], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

译文

路径为[]的上下文中Servlet[dispatcherServlet]的Servlet.service()引发异常[请求处理失败;嵌套异常为org.thymeleaf.exceptions.TemplateInputException:解析模板[success]时出错,模板可能不存在,或者任何已配置的模板解析程序都无法访问该模板,其根本原因是

改错

在html页面里有原来的

<html lang="en">改为<html lang="en" xmlns:th="http://www.thymeleaf.org">即可

前端错误 thymeleaf ${xxx} Cannot resolve 报错
问题描述

最近做了一个springboot项目,集成了thymeleaf,在使用thymeleaf的过程中遇到了一个问题,就是“${xxx}”下面总是报“Cannot resolve ‘xxx’”的错误,如下图所示:

这个错误的意思是无法解析(读取)‘xxx’边的值。

 
问题原因
遇到问题了,赶紧排查一下到底是哪出问题了。

猜想一
由于是集成的thymeleaf,猜想是不是在集成thymeleaf的过程中哪一步出错了,才导致此问题的出现。于是详细地检查了每一个步骤,都没有问题。于是我启动了项目,想通过试运行看看能不能得到更多的信息以用来解决问题,但是神奇的事情出现了,页面居然获取到值了,amazing!

这就比较奇怪了,既然集成thymeleaf没有出错,页面也能读取到值,为什么还会报错呢?到底问题出在哪里?

此时我脑子里闪过一个想法,我使用的开发工具是IDEA啊,使用这款开发工具是因为极其强大的提示功能,于是有了猜想二。

猜想二
一般的开发工具只会语法进行检验,只要语法没问题就不会报错。

但是IDEA除了对语法检验之外,还对表达式进行检验。IDEA检测到html是不支持El表达式的,所以才会有“Cannot resolve”的提示。

虽然html不可以使用此表达式,但是thymeleaf可以使用啊,项目中又集成了thymeleaf,所以运行项目是可以读取到值的。

总结
也就是说,这并不是解析错误,而是IDEA检测到不支持这种写法而给你的提示:不能这样写,这样写会出错。

但是在强大的工具也只是工具,只会按照既定的逻辑去走,不会懂得变通。


解决方法
但是作为程序员来说,都是有强迫症,你懂得。既然清楚了问题原因,就好说了,下面提供两个方法解决这个问题。

方法一
加注释解决,这种方法也是IDEA提示的解决此问题的方法,但提示的不一定是最好的。如下图所示:
 

只有一处还好说,要是有多处使用的话,那么每一处都要加注释,若是只有这一种方法,那就没得说了。但要是有其他的解决方法,这种方法就不可取了。

方法二
尽然是IDEA检验导致的问题,那我们就从根源上解决问题,不让IDEA做这方面的检验不就OK了。

emmmm。。。。不愧是是我😁(请原谅我的厚脸皮😂)。

点击“File”->“Settings”->“Editor”->“Inspection”,如果东西太多一时找不到,可以在输入框中输入“thy”就会很快找到thymeleaf插件,取消“Expression variables validation”的勾选,点击“Apply”再点击“OK”就行了。
 

看一下页面,提示没有了,大功告成!

错误

Springboot错误--would dispatch back to the current handler URL [/XXX] again. Check your ViewResolv

控制台显示的错误:

2018-07-30 11:59:49.911 ERROR 17344 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [adPlace]: would dispatch back to the current handler URL [/adPlace] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause

javax.servlet.ServletException: Circular view path [adPlace]: would dispatch back to the current handler URL [/adPlace] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation
 

解决方法:
把@Controller改成@RestController

错误

  : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template [userAjax], 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 [userAjax], template might not exist or might not be accessible by any of the configured Template Resolvers
    at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]

错误原因

在return返回页面时页面的名字写错了,

改错:只需将页面的名字改正确即可;

数据库的错误

在表中插入数据时报错:

insert  into fa values (null,dhljkf)
1054 - Unknown column 'dhljkf' in 'field list'
时间: 0.001s

错误原因:

在插入数据时在字符串或汉字没有加引号

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值