记录一个异常的解决办法 This application has no explicit mapping for /error, so you are seeing this as a fallback.
- 后端异常显示
Field error in object 'user' on field 'id': rejected value [null]; codes [typeMismatch.user.id,typeMismatch.id,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.id,id]; arguments []; default message [id]]; default message [Failed to convert value of type 'null' to required type 'int'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [int] for value 'null'; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type]]
原因4 : 解决办法,给实体类User加上默认的构造函数。
网友给出了可能的3种原因,我都不是,那我给出原因4吧。
原因1: Application启动类的位置不对.要将Application类放在最外侧,即包含所有子包 原因:spring-boot会自动加载启动类所在包下及其子包下的所有组件.
原因2: 在springboot的配置文件:application.yml或application.properties中关于视图解析器的配置问题: 当pom文件下的spring-boot-starter-paren版本高时使用: spring.mvc.view.prefix/spring.mvc.view.suffix 当pom文件下的spring-boot-starter-paren版本低时使用: spring.view.prefix/spring.view.suffix
原因3: 控制器的URL路径书写问题 @RequestMapping(“xxxxxxxxxxxxxx”) 实际访问的路径与”xxx”不符合.