Mapper中这样写:

@UpdateProvider(type = SjjcSqlProvider.class, method = "updateTaskStatusByCBh")
int updateTaskStatusByCBh(@Param("list") List<String> list);

SjjcSqlProvider中这样写:

public String updateTaskStatusByCBh(Map<String, Object> parameters) {
List<String> list = (List<String>) parameters.get("list");
StringBuilder sb = new StringBuilder();
sb.append("update db_yw.t_sjjc_task as task ");
sb.append("set n_zt=6 ");
sb.append("where task.c_bh in");
sb.append("(");
for (int i = 0; i < list.size(); i++) {
sb.append("'");
sb.append(list.get(i));
sb.append("'");
if (i < list.size() - 1) {
sb.append(",");
}
}
sb.append(")");
return sb.toString();
}

最后,传入list列表就可以批量的根据主键更新表中的某一个字段了

05-29 01:30