跳到主要内容

@Update 注解

用来标记在接口方法上,执行一个 UPDATE 语句。

信息

如果传入的是一个字符串数组,它们会被连接起来,中间用一个空格隔开。
通过字符串数组可以更清晰地管理多行 SQL。

示例:根据 id 字段更新 name 字段
@SimpleMapper
public interface UserMapper {
@Update({"update users", // 1. 定义 SQL 语句
"set name = #{newName}", //
"where id = #{userId}"}) //
int updateUserName( // 2. userId 和 newName 参数
@Param("userId") int userId,
@Param("newName") String newName
);
}

属性清单

属性名描述
value必选 将要被执行的 UPDATE 语句。
statementType可选 JDBC 执行使用何种方式。默认值为 Prepared
- Statement 对应 java.sql.Statement
- Prepared 对应 java.sql.PreparedStatement
- Callable 对应 java.sql.CallableStatement
timeout可选 设置执行超时时间(秒),会调用 Statement.setQueryTimeout(int)。默认值 -1 表示不设置