May 14, 2021 JFinal manual
Model defines the sample code:
public class User extends Model<User> {By inheriting Model, User in the above code immediately has a number of convenient ways to operate the database. A dao static object declared in User is defined for ease of query operations and is not required. ActiveRecord-based Model eliminates the need to define properties, getter, setter methods, XML configuration, Annotation configuration, and significantly reduces the amount of code.
public static final User dao = new User();
}
Create a User object with a name property of James and an age property of 25 and add it to the database
new User().set("name", "James").set("age", 25).save();
Remove User User with an id value of 25. dao .deleteById(25);
User, which has a query id value of 25, changed its name property to James and updated it to the database
User. dao .findByIdLoadColumns (25).set("name", "James").update();
The query id is a user with a value of 25, and only the values of the two fields name andage are taken
User user = User. dao .findByIdLoadColumns (25, "name, age");
Gets the name property of the user
String userName = user.getStr("name");
Gets the age property of the user
Integer userAge = user.getInt("age");
Find out all user over 18 years of age
List<User> users = User. dao .find("select * from user where age>18");
Paged queries for user older than 18, with the current page number of 1, with 10 user per page
Page<User> userPage = User. dao .paginate(1, 10, "select *", "from user where age > ?", 18);
Note in particular: The public static final User dao object defined in User is globally shared and can only be used for database queries and not for data-hosting objects. D ata hosting requires the use of new User(.set(...) to achieve.