栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

前端异步提交数据报错Error getting generated key or setting result to parameter object及解决方法

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

前端异步提交数据报错Error getting generated key or setting result to parameter object及解决方法

出问题的功能为:前端用ajax(axious)异步添加品牌数据报错
### 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设为null
brand: {
                    status: '',
                    companyName: '',
                    brandName: '',
                    id:null,
                    ordered:'',
                    description:''
                },
就不会报错了 总结id:"",就会把空字符串最终传递给mapper.xml,错误接收id属性,报这样的错误:Error getting generated key

        insert into tb_brand (brand_name, company_name, ordered, description, status)
        values (#{brandName},#{companyName},#{ordered},#{description},#{status});
    
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/737060.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号