This article introduces the simple example of IBATIS's SQL Map. It is a free open source software. With the following advantages: 10, know how to operate more than 10 kinds of databases 9, configurable CACHING (including slave) 8, support DataSource, Local Transaction Managemen, and Global Transaction 7, Simple XML Configuration Document 6, support MAP, Collection, List And simple type packaging (such as Integer, String) 5, support JavaBeans class (GET / SET Method) 4, support complex object mapping (such as Populating Lists, Complex Object Models) 3, the object model is not perfect (no need to modify) 2 The data model is never perfect (no need to modify) 1, you already know SQL, why do you want to learn other things?
The following is http://www.ibatis.com/common/example.html Chinese translation, translation is not good, please forgive me.
The following is a simple SQL MAP example. This query statement uses the feature of the SQL Map framework, allowing the database field name to automatically map to the Javabean property. Suppose there are several properties in the Address class: ID (int), description (string), street (string), city (string), postalcode (string) in the SQL statement (a standard SQL feature) By using the field alias and name the Class in the Result-Class property, the value in the field will be automatically mapped to the JavaBean. This is a method of obtaining an object (javabean) from the SQL MAP framework from the SQL query statement. ->
How do I use Java to do it?
/ * * The following lines pass the Integer 5 to the # value # parameter in the above statement to perform the mapping statement. * /
Integer pk = new integer (5); address address = (address) SQLMap.QueryForObject ("getaddress", PK);
// Tip: View JPETSTORE 4, which uses many new features, it is a complete application instance. At the same time, there is a complete documentation of a detailed development guide. // More examples, please see below.
Address Address (); address.setId (15); address.setdescription ("Bob's COMIC BOOK Store"; address.setstreet ("16 Somestreet"); ... SQLMap.insert ("Insertaddress", Address ;
/ / Get a product list in a "Dog" class to perform the above statement, just like this:
String category = "DOG"; list productlist = SQLMap.QueryforList ("getProductBycategory", category;
// Too many results? Then fully navigate, lazy-loaded, use JavaBean to list the product, // How is the ease of use in the JSP page? 10 rows on a page?
PaginatedList productList = Sqlmap.QueryforList ("GetProductBycategory", Category, 10);
ProductList.nextPage (); productlist.previouspage (); productList.isnextpageavailable (); // etc.
/ / Nea need a product ID from the same query and the map described?
Map descriptionMap = SQLMap.QueryFormap ("getProductBycategory", category, "id", "description");
Integer Managerid = New Integer (15); List Employeelist = Sqlmap.QueryforList ("GetEmployeesbymanagerRecursively", ManagerID;