错误信息
01-May-2020 20:43:35.866 WARNING [http-nio-555-exec-1] org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.logException Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object ‘books’ on field ‘bookId’: rejected value [null]; codes [typeMismatch.books.bookId,typeMismatch.bookId,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [books.bookId,bookId]; arguments []; default message [bookId]]; 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]]
解决方法
底层的books的参数重写为bookID
PS: 但是当我重写回bookId的时候又没有问题了,怀疑是idea有bug
下面是Books类的代码,一开始bookId报错,重写成bookID后不报错了,但是再次重写成bookId不报错.
package com.psj.pojo;
public class Books {
private int bookId;