Skip to content

Save to DB

王爵nice edited this page Mar 17, 2018 · 1 revision

Saving data through Anima is a process of persisting a Java object to a database, so you only need to create an object and then save it. Anima will return you a ResultKey object through which you can save the database. The primary key.

User user = new User();
user.setUserName("save1");
user.setAge(99);
Integer id = user.save().asInt();

You can also save it with the ʻAnimastatic methodssaveandsaveBatch`.

Anima.save(new User("save3", 100));
List<User> users = new ArrayList<>();
users.add(new User("user1", 10));
users.add(new User("user2", 11));
users.add(new User("user3", 12));
Anima.saveBatch(users);
Clone this wiki locally