Using ActiveRecord in a non-web environment
ActiveRecordPlugin can run in any ordinary Java program independently of the Java web environment. It is extremely simple to use. Compared with web projects, you only need to manually call its start() method to use it immediately. The following is a code example:
public class ActiveRecordTest {
public static void main(String[] args) {
DruidPlugin dp = new DruidPlugin("localhost", "userName", " password"); ActiveRecordPlugin arp = new ActiveRecordPlugin(dp); arp.addMapping("blog", Blog.class);
// The only difference from the web environment is that you need to manually call the start( of the relevant plug-in )Method
dp.start();
arp.start();
// With the simple lines of code above, you can start using
new Blog().set immediately ("title", "title").set("content", "cxt text").save(); Blog.me.findById(123);
}
}
public static void main(String[] args) {
DruidPlugin dp = new DruidPlugin("localhost", "userName", " password"); ActiveRecordPlugin arp = new ActiveRecordPlugin(dp); arp.addMapping("blog", Blog.class);
// The only difference from the web environment is that you need to manually call the start( of the relevant plug-in )Method
dp.start();
arp.start();
// With the simple lines of code above, you can start using
new Blog().set immediately ("title", "title").set("content", "cxt text").save(); Blog.me.findById(123);
}
}
Note: Other plug-ins that ActiveRecordPlugin depends on must also manually call the start() method, such as dp.start() in the above example.