List<SysUser> selectbatch (@Param("list") BatChSysUserDTO batChSysUserDTO);
<select id="selectbatch" resultType="com.example.demo.entity.SysUser">
    SELECT * FROM  sys_user
             where name in
    <foreach item="item" collection="list.name" open="(" separator="," close=")">
        #{item}
    </foreach>
</select>
public class CheckComentEntity {
  /*t_check_coment*/
  private Long    id;
  @JsonSerialize(using = ToStringSerializer.class)
  private Long    checkId;
  private String  checkCategory;
  private String  checkType;
  private String  checkConment;
  private String  riskLevel;
  private String  description;
  private String  remark;
  private String  isInput;
  private String  business;
  private String  itemName;
  private Date    createTime;
  private Date    updateTime;
  private Integer checkResult;
  private String  questionDescription;

mapper 层

void addCheckConment(@Param("list") List<CheckComentEntity> list);
<insert id="addCheckConment" parameterType="java.util.List">
    insert into
        t_check_conment_save
        (check_id,check_type,check_conment,risk_level,description,remark,check_result,check_conment_status,create_time,update_time,item_name,question_description)
    values
    <foreach collection="list" item="item" index="index" separator=",">
        #{item.checkId},#{item.checkType},#{item.checkConment},#{item.riskLevel},
         #{item.description},#{item.remark},#{item.checkResult},'0',now(),now(),#{item.itemName},#{item.questionDescription}
    </foreach>
</insert>
index:通过下标0,1,2来循环取出每个元素(index="index") item:每循环一次所取出的参数 取别名,这个可以随便填,与#{items}表达式的参数对应(item="items") separator...
foreach元素的属性主要有 collection,item,index,separator,open,close。 collection:表示集合,数据源 item :表示集合的每一个元素 index :用于表示在迭代过程,每次迭代到的位置 separator :表示在迭代时数据以什么符号作为分隔符 open :表示该语句以什么开始 close :表示以什么结束
foreach的主要用在构建in条件,它可以在SQL语句进行迭代一个集合。 foreach元素的属性主要有 item,index,collection,open,separator,close。 item表示集合每一个元素进行迭代时的别名 index指 定一个名字,用于表示在迭代过程,每次迭代到的位置 separator表示在每次进行迭代之间以什么符号作为分隔符 open表示该语句以...
将Mapper接口定义的SQL语句写到xml文件,需要按照以下步骤进行操作: 1. 在resources目录下创建一个与Mapper接口同名的xml文件,例如UserMapper.xml。 2. 在xml文件添加一个mapper标签,并设置namespace属性为Mapper接口的全限定名,例如com.example.mapper.UserMapper。 3. 在mapper标签添加一个select标签,并设置id属性为Mapper接口定义的方法名,例如getUserById。 4. 在select标签添加SQL语句,例如SELECT * FROM user WHERE id = #{id}。 5. 在Mapper接口添加@Mapper注解,并使用@Select注解指定SQL语句的id,例如@Select("getUserById")。 6. 在需要使用Mapper接口的地方注入Mapper接口的实例,并调用其的方法即可。 注意:在xml文件,可以使用if、where、foreach等标签来动态生成SQL语句。同时,需要保证Mapper接口定义的方法名与xml文件定义的id属性名一致。