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

5.13 ActiveRecord is used in a non-web environment


May 14, 2021 JFinal manual



ActiveRecordPlugin can run independently of the java web environment in any normal java program and is extremely simple to use, as opposed to web projects that require only a manual call of its start() method for immediate use. Here's an example of the code:

public class ActiveRecordTest {
public static void main(String[] args) {
DruidPlugin dp = new DruidPlugin("localhost", "userName", "password"); A ctiveRecordPlugin arp = new ActiveRecordPlugin(dp); arp.addMapping("blog", Blog. class );

The only difference with a web environment is that you manually call the start() method of the relevant plug-in once
dp.start();
arp.start();

With a few simple lines of code above, you can get started right away
new B log().set("title", "title").set("content", "cxt text").save(); B log. me .findById(123);
}
}

Note: Other plug-ins on which ActiveRecordPlugin depends must also manually call the start() method, such as dp.start() in the example above.