-
Notifications
You must be signed in to change notification settings - Fork 46
更新和删除
王爵nice edited this page Mar 19, 2018
·
2 revisions
数据库方式更新
String newName = "biezhi_" + System.currentTimeMillis();
int result = update().from(User.class).set("user_name", newName).execute();
// UPDATE users SET user_name = ?
result = update().from(User.class).set("user_name", newName).where("id", 1).execute();
// UPDATE users SET user_name = ? WHERE id = ?
实例对象更新
User user = new User();
user.setId(1);
user.setAge(22);
user.setUserName("jack");
user.update();
// UPDATE users SET age = ?, user_name = ? WHERE id = ?
根据主键更新
new User().set("user_name", "jack").updateById(3);
lambda表达式更新
update().from(User.class).set(User::getUserName, "base64").updateById(3);
update().from(User.class).set(User::getUserName, "base64").where(User::getId).eq(2).execute();
int result = delete().from(User.class).where("id", 1).execute();
使用实例方法删除
User user = new User();
user.setAge(15);
user.setUserName("jack");
user.delete();
根据主键删除
Anima.deleteById(User.class, 5);
批量删除
Anima.deleteBatch(User.class, 1, 2, 3);
Anima.deleteBatch(User.class, List<Integer>);
lambda表达式删除
delete().from(User.class).where(User::getId).eq(1).execute();
delete().from(User.class).where(User::getAge).lte(20).execute();
Contributing
Documentation
- Getting started
- Create Model
- Query DB
- Save to DB
- Updates and Deletes
- Transaction
- Integration with Spring
- Advanced Usage
Other resources
中文文档