Field error in object 'book' on field 'bookId': rejected value [null]; codes
[typeMismatch.book.bookId,typeMismatch.bookId,typeMismatch.int,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes [book.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]]
提交表单的时候,没有上传booId的数据的,后来我发现,实体类里面我写少了了一个无参构造器,查了一下百度,说是和java反射有关,也有说不写也行的,反正我加了无参构造器就可以了。
我在想,是不是没有无参构造器,我们传值得时候也没有传给这个booId属性,所以默认值就会是null,有了无参构造器之后就是0.后来调试发现,好像是这样子,个人见解,有错希望大佬们指正。