// 更新用户名为 'John' 的用户的年龄为 30
new UpdateChainWrapper<>(User.class)
.eq("name", "John")
.set("age", 30)
.update();
// 将年龄大于 18 且用户名为 'John' 的用户的状态设为激活
new UpdateChainWrapper<>(User.class)
.gt("age", 18)
.eq("name", "John")
.set("status", "active")
.update();
// 将所有用户的状态设置为激活
new UpdateChainWrapper<>(User.class)
.set("status", "active")
.update();
// 更新用户名为 'John' 的用户的邮箱
new UpdateChainWrapper<>(User.class)
.eq("name", "John")
.set("email", "john@example.com")
.update();
// 将用户名为 'John' 且年龄大于 30 的用户的状态设为非激活
new UpdateChainWrapper<>(User.class)
.eq("name", "John")
.gt("age", 30)
.set("status", "inactive")
.update();
// 更新所有用户的信息,但不更新邮箱字段
new UpdateChainWrapper<>(User.class)
.set("name", "Updated Name")
.set("age", 25)
.update(new UpdateWrapper<User>().excludeColumns("email"));
// 根据用户的当前状态动态更新其状态
new UpdateChainWrapper<>(User.class)
.setSql("status = CASE WHEN status = 'active' THEN 'inactive' ELSE 'active' END")
.update();
// 更新用户名为 'John' 的用户的年龄和邮箱
new UpdateChainWrapper<>(User.class)
.eq("name", "John")
.set("age", 35)
.set("email", "newjohn@example.com")
.update();
// 将年龄在 20 到 30 之间的用户的状态更新为激活
new UpdateChainWrapper<>(User.class)
.between("age", 20, 30)
.set("status", "active")
.update();
// 复杂条件组合:将年龄大于 18 并且名字包含 'John' 的用户的状态更新为激活
new UpdateChainWrapper<>(User.class)
.gt("age", 18)
.like("name", "John")
.set("status", "active")
.update();