Small test iBatis (good)

xiaoxiao2021-03-06  50

Ibatis is another o / r mapping solution, J2EE's O / R scheme is much more, compared with Hibernate, iBATIS is small, it is very fast. If you don't need too much complex feature, iBATIS is the easiest solution to meet your requirements and flexible solutions. The biggest feature of IBATIS is simple, the latest version 2.0 (download), compared with 1.0, mainly modified on the XML configuration file, but as long as there is SQL foundation, I believe that you can see it without tutorial. Let's take a look at a simplest example. We first build a table Account, including the field username, varchar (20), PK, and Password, Varchar (20), where some data is filled in. Then write IBATI must have the configuration file SQL-MAP-Config.xml, the file name is free, the content is as follows: Other parts You don't need to manage it, I am directly Copy's sample configuration, just pay attention to the red part, configure the data source. I use Access, so use JDBCODBC drivers. If you use mysql or other database, change the appropriate properties.

Then note that this profile also references an account.xml, it's right, iBatis associates each Java object that requires o / r mapping to an XML configuration file, we need to map an Account table to an Account class: package eXample ; public class Account {private String username; private String password; public String getUsername () {return username;} public void setUsername (String username) {this.username = username;} public String getPassword () {return password;} public void SetPassword (String password) {this.password = password;}} Written an Account.xml file: as an example, define a query method, the name is getaccount, the incoming parameter is string, return type Resultclass is an example.account class, SELECT statement believes that you are already familiar, # value # is us String will be passed in. , but notes # username # and # password #, because the parameters are Account class, they will be replaced by Account.getUserName () and Account.getPassword (). So, as long as you write SQL, you can easily write the configuration file very easily. Finally, how to use IBATI to implement O / R mapping.

转载请注明原文地址:https://www.9cbs.com/read-109890.html

New Post(0)