<?xml version="1.0" encoding="utf-8" ?> <sqlMap namespace="Product" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <alias> <!--商品别名--> <typeAlias alias="Product" type="OMS.DTL.Entities.Product,OMS.DTL" /> <!--商品部分属性别名--> <typeAlias alias="ProductPartial" type="OMS.DTL.Entities.ProductPartial,OMS.DTL"/> <!--商品查询条件别名--> <typeAlias alias="ProductQueryCondition" type="OMS.DTL.Entities.ProductQueryCondition,OMS.DTL"/> </alias> <!--结果映射--> <resultMaps> <resultMap id="ProductPartial" class="ProductPartial"> <result property="ProductID" column="ProductID"/> <result property="ProductName" column="ProductName"/> <result property="QuantityPerUnit" column="QuantityPerUnit"/> <result property="UnitPrice" column="UnitPrice" /> <result property="UnitsInStock" column="UnitsInStock"/> </resultMap> </resultMaps> <statements> <!--查询所有商品--> <select id="SelectAllProduct" resultClass="Product"> SELECT [ProductID] ,[ProductName] ,[SupplierID] ,[CategoryID] ,[QuantityPerUnit] ,[UnitPrice] ,[UnitsInStock] ,[UnitsOnOrder] ,[ReorderLevel] ,[Discontinued] FROM [Products] </select> <!--根据商品ID查询商品--> <select id="SelectProductByProductID" parameterClass="int" resultClass="Product" extends="SelectAllProduct"> WHERE ProductID=#PorductID# </select> <!--获取所有产品的部分信息--> <select id="SelectAllProductPartial" resultMap="ProductPartial"> SELECT [ProductID] ,[ProductName] ,[SupplierID] ,[CategoryID] ,[QuantityPerUnit] ,[UnitPrice] ,[UnitsInStock] ,[UnitsOnOrder] ,[ReorderLevel] ,[Discontinued] FROM [Products] </select> <!--通过两个条件或的关系查找--> <!--通过字典传值--> <select id="SelectProductByIDOrName" parameterClass="System.Collections.IDictionary" resultClass="Product" extends="SelectAllProduct"> WHERE ProductID=#ProductID# OR ProductName=#ProductName# </select> <!--通过类传值--> <select id="SelectProductBySupplierIDOrCategoryID" parameterClass="ProductQueryCondition" resultClass="Product" extends="SelectAllProduct"> WHERE SupplierID=#SupplierID# OR CategoryID=#CategoryID# </select> <!--插入操作--> <insert id="Insert" parameterClass="Product"> INSERT INTO [Products] ([ProductName] ,[SupplierID] ,[CategoryID] ,[QuantityPerUnit] ,[UnitPrice] ,[UnitsInStock] ,[UnitsOnOrder] ,[ReorderLevel] ,[Discontinued]) VALUES (#ProductName# ,#SupplierID# ,#CategoryID# ,#QuantityPerUnit# ,#UnitPrice# ,#UnitsInStock# ,#UnitsOnOrder# ,#ReorderLevel# ,#Discontinued#) <!--获取自增列ID--> <selectKey resultClass="int" type="post" property="ProductID" > select @@IDENTITY as value </selectKey> </insert> <!--更新操作--> <update id="Update" parameterClass="System.Collections.IDictionary"> update Products set ProductName = #ProductName# where ProductID = #ProductID# </update> <!--删除操作--> <delete id="Delete" parameterClass="int"> Delete From Products Where ProductID=#ProductID# </delete> </statements> </sqlMap>