Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

5.2 ActiveRecordPlugin


May 14, 2021 JFinal manual



ActiveRecord exists as JFinal Plugin, so activeRecordPlugin needs to be configured in JFinalConfig when used.

Here's 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. c lass ); A rp. ping ("article", "article_id", Article . class );
}
}

The above code is configured with two plug-ins: C3p0Plugin, which is a c3p0 data source plug-in, and ActiveRecord Plugin, which is an ActiveRecrod support plug-in. ActiveReceord defines the addMapping (String tableName, Class<extends Model?model?gt;) method, which establishes a mapping relationship from the database table name to the Model.


In addition, in the above code arp.addMapping ("user", User.class), the primary key name of the table is "id" by default, and if the primary key name is "user_id", you need to specify it manually, such as arp.addMapping ("user", "user_id", User.class).