带xml
*/
/* sale_orders销售订单表 sale_order_details销售订单细表 products商品表 product_catalogs商品类别表 从sql中就可以分析出 id是主鍵 sale_order_details.sale_order_id===>sale_orders.id sale_order_details.product_catalog_id==>product_catalogs.id sale_order_details.product_id==>products.id */ String []sqls=new String []{ " select id, total_sum, memo, state, modify_date, creator, checker from sale_orders ", " select id, sale_order_id, product_id, product_name, product_catalog_id, model, product_unit, product_amount, product_price, product_sum, memo from sale_order_details ", " select id, name, catalog, model, price, unit, memo, createtime, state, code, productno from products ", " select id, name, memo from product_catalogs" }; /*<?xml version="1.0"?><MapObject><!--类似hibernate的映射,但是更容易理解,而且可以省略字段映射--> <Object tablename="sale_orders" class="org.test.pojo.SaleOrder"> <OneToMany tablename="sale_order_details" class="org.test.pojo.SaleOrderDetail"> <!--主细表映射--> <ParentKey>id</ParentKey> <ChildKey>id</ChildKey> </OneToMany> <!--字段映射可选,一般是相同或根据ROR规则--> <FieldMap>可选...</FieldMap> </Object> <Object tablename="sale_order_details" class="org.test.pojo.SaleOrderDetail"> <!-- 附加代码表映射1对1关系 --> <OneToOne tablename="products" class="org.test.pojo.Product"> <ParentKey tablename="sale_order_details">product_id</ParentKey> <ChildKey tablename="products">id</ChildKey> </OneToMany> <FieldMap>可选...</FieldMap> </Object> <Object tablename="sale_order_details" class="org.test.pojo.SaleOrderDetail"> <OneToOne tablename="product_catalogs" class="org.test.pojo.ProductCatalog"> <ParentKey tablename="sale_order_details">product_catalog_id</ParentKey> <ChildKey tablename="product_catalogs">id</ChildKey> </OneToMany> <FieldMap>可选...</FieldMap> </Object> <Object tablename="product_catalogs" class="org.test.pojo.ProductCatalog"> <FieldMap>可选...</FieldMap> </Object></MapObject> */ String xml="..."; //带xml映射 List l=SQLMapObjects(conn,sqls,xml); /* l的结构: sale_orders[] |-----sale_order_details[](sale_order_details.sale_order_id===>sale_orders.id) |-----products[](sale_order_details.product_id==>products.id) |-----product_catalogs[](sale_order_details.product_catalog_id==>product_catalogs.id) */
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/