### Error updating database、 Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object、Cause: org.apache.ibatis.executor.ExecutorException: No setter found for the keyProperty 'id' in 'java.lang.Class'.### The error may exist in com/example/mapper/BrandMapper.xml### The error may involve defaultParameterMap### The error occurred while setting parameters### SQL: insert into tb_brand (brand_name, company_name, ordered, description, status) values (?,?,?,?,?);### Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object、Cause: org.apache.ibatis.executor.ExecutorException: No setter found for the keyProperty 'id' in 'java.lang.Class'.
后台添加代码没问题(注:利用自增,没setId)BrandService brandService = new BrandService(); Brand brand = new Brand(); brand.setBrandName("波导"); brand.setCompanyName("波导手机"); brand.setOrdered(103); brand.setDescription("手机中的战斗机"); brand.setStatus(0); brandService.addBrand(brand); [DEBUG] 21:16:35.469 [main] c.e.m.B.add - ==> Preparing: insert into tb_brand (brand_name, company_name, ordered, description, status) values (?,?,?,?,?);
前端提交Bean报错,最后发现为模型传递错误brand: { status: '', companyName: '', brandName: '', id:'', ordered:'', description:'' },
这里id设置为"",才导致参数传递错误 id:"" 应该为这样,将id设为nullbrand: { status: '', companyName: '', brandName: '', id:null, ordered:'', description:'' },
就不会报错了 总结id:"",就会把空字符串最终传递给mapper.xml,错误接收id属性,报这样的错误:Error getting generated key