用mybatis插入数据到数据库,都写好了,就是报错:
Caused by: org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found. Available parameters are [collection, list]
解决:其实全是粗心的问题,把所有参数检测完了,发现字段写错了还是报这个错。细心点就没问题,参数,sql字段都检查好。参数个数,名称,类型都对得上就可以了。
dao:
int insert(List<OrderDetail> OrderDetailList);
sql:
<insert id="insert" parameterType="OrderDetail"> insert into p_order_detail(order_id,product_id,product_detail_id,product_sku_code,product_name,product_sku_name,unit_name,require_num,plan_date,description,status_text,status_code) values <foreach collection="list" item="item" separator="," > (#{item.orderId},#{item.productId},#{item.productDetailId},#{item.productSkuCode},#{item.productName},#{item.productSkuName},#{item.unitName},#{item.requireNum},#{item.planDate},#{item.description},#{item.statusText},#{item.statusCode}) </foreach> </insert>
注:另外批量插入,我一般都时把前端传来的参数直接转bean,直接转bean要注意用合适的方法
List<OrderDetail> OrderDetailList=new ArrayList<OrderDetail>(); OrderDetailList= mapper.readValue(orderDTO.getOrderDetail(),mapper.getTypeFactory().constructCollectionType(OrderDetailList.getClass(), OrderDetail.class));