Mybatis 中传入数组类型参数批量更新表数据的写法
假设有个文章表,表字段有:文章ID,状态,作者ID,标题,创建时间。
文章表在 Mybatis 的 xml 文件里的定义:
<resultMap id="BaseResultMap" type="com.test.entity.ArticleEntity" >
<id column="AUTHORID" property="authorid" jdbcType="INTEGER" />
<result column="STATE" property="state" jdbcType="TINYINT" />
<result column="CREATORID" property="creatorid" jdbcType="INTEGER" />
<result column="TITLE" property="title" jdbcType="VARCHAR" />
<result column="CRTTIME" property="crttime" jdbcType="TIMESTAMP" />
</resultMap>
某作者想删除他的5个文章,传入参数是文章ID的数组、状态值(删除)、作者ID,那么代码写法如下。
后端 JAVA 函数的定义:
int updateBatchStateByPrimaryKeySelective(@Param("arrArticleid") Integer[] arrArticleid, @Param("state") Byte state, @Param("userid") Integer userid);
Mybatis 的 SQL 语句写法:
<update id="updateBatchStateByPrimaryKe