项目场景:
报错 ,找不到参数
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘statusInfoId’ not found. Available parameters are [collection, list]
@Mapper
public interface PatrolRecordMapper extends BaseMapper<PatrolRecord> {
int insertList(@Param(value = "list") List<PatrolRecord> list);
}
mapper 换了很多种写法
<insert id="insertList" parameterType="com.iricto.soft.patrol.entity.PatrolRecord">
insert into patrol_record(status_info_id,route_id,place_name,patrol_time,
patrol_user,patrol_class,`status`)
VALUES
<foreach collection="list" item="patrolRecord" separator=",">
(patrolRecord.#{statusInfoId},
patrolRecord.#{routeId},
patrolRecord.#{placeName},
patrolRecord.#{patrolTime},
patrolRecord.#{patrolUser},
patrolRecord.#{patrolClass},
patrolRecord.#{status})
</foreach>
</insert>
mapper
<insert id="insertList" parameterType="com.iricto.soft.patrol.entity.PatrolRecord">
insert into patrol_record(status_info_id,route_id,place_name,patrol_time,
patrol_user,patrol_class,`status`)
VALUES
<foreach collection="list" item="list"
open="(" separator="," close=")">
list.#{statusInfoId},
list.#{routeId},
list.#{placeName},
list.#{patrolTime},
list.#{patrolUser},
list.#{patrolClass},
list.#{status}
</foreach>
</insert>
最后应该这么写才对 : mapper
<insert id="insertList" parameterType="com.iricto.soft.patrol.entity.PatrolRecord">
insert into patrol_record(status_info_id,route_id,place_name,patrol_time,
patrol_user,patrol_class,`status`)
VALUES
<foreach collection="list" item="patrolRecord" separator=",">
(
#{patrolRecord.statusInfoId},
#{patrolRecord.routeId},
#{patrolRecord.placeName},
#{patrolRecord.patrolTime},
#{patrolRecord.patrolUser},
#{patrolRecord.patrolClass},
#{patrolRecord.status})
</foreach>
</insert>