ActiveRecordPlugin
ActiveRecord exists as a Plugin of JFinal, so you need to configure ActiveRecordPlugin in JFinalConfig when using it.
The following is the Plugin configuration sample code:
public class DemoConfig extends JFinalConfig {
public void configPlugin(Plugins me) {
C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost/db_name ", "userName", "password");
me.add(cp);
ActiveRecordPlugin arp = new ActiveRecordPlugin(cp) ; me.add(arp);
arp.addMapping("user", User.class); arp.addMapping("article", "article_id", Article.class);
}
}
The above code configures two plug-ins: C3p0Plugin and ActiveRecordPlugin. The former is the c3p0 data source plug-in, and the latter is the ActiveRecrod support plug-in. The addMapping(String tableName, Class<? extends Model> modelClass>) method is defined in ActiveReceord, which establishes the mapping relationship between the database table name and the Model.
In addition, in the above code arp.addMapping("user", User.class), the primary key name of the table defaults to "id". If the primary key name is "user_id ” needs to be specified manually, such as: arp.addMapping(“user”, “user_id”, User.class).