IBatis Calling stored Procedures
Http://www.cnblogs.com/jeffwongishandsome/archive/2010/01/10/1543219.html
Http://www.cnblogs.com/firstyi/archive/2008/01/25/1053208.html
Stored procedures are broadly divided into two types:
- Query class stored procedure--select query the stored procedure of the class, not change the stored procedure of database data
- Update a stored procedure of class stored procedure--update/insert/delete type, change the stored procedure of database data
Ibatis.net call the stored procedure:
1. Query type of stored procedure
Create a query class stored procedure that contains the output parameters.
CREATE PROCEDURE up_getcountbytitle @title VARCHAR , @total INT out as BEGIN With a as ( '%'[email protected]+'%' ) SELECT @total=count (*) from a END
get the total number of stored procedures
The XML file, if it contains output parameters, output parameter property values, must contain the column property.
<?XML version= "1.0" encoding= "Utf-8"?><Sqlmapnamespace= "article"xmlns= "Http://ibatis.apache.org/mapping"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"> <alias> <Typealiasalias= "article"type= "YY. Micronet.model.article,yy. Micronet.model "/> </alias> <Resultmaps> <ResultmapID= "Fullresultmap"class= "article"> <result Property= "Pkarticle"column= "Pk_article"DbType= "VarChar"/> <result Property= "ArticleTitle"column= "ArticleTitle"DbType= "NVarChar"/> <result Property= "Articleauthor"column= "Articleauthor"DbType= "NVarChar"/> <result Property= "Articlecontent"column= "Articlecontent"DbType= "NVarChar"/> <result Property= "EditTime"column= "EditTime"DbType= "DateTime"/> <result Property= "Dr"column= "Dr"DbType= "Bit"/> <result Property= "Ts"column= "Ts"DbType= "DateTime"/> </Resultmap> <Parametermaps> <!--the number and order of parameters in Parametermap are consistent with the Up_getcountbytitle stored procedure - <ParametermapID= "params"class= "Hashtable"> <parameter Property= "title" /> <parameter Property= "Total"column= "Total"direction= "Output"/> </Parametermap> </Parametermaps> </Resultmaps> <Statements> <!--calling a stored procedure of a query type - <procedureID= "Article_getcountbytitle"Parametermap=""ResultClass= "System.Int32">Up_getcountbytitle</procedure> </Statements></Sqlmap>
Articlemap.xml
Called in CS
Public ilist<article> Getcountbytitle (Hashtable ht) { String stmtid = "Article_getcountbytitle"; ilist<article> result = sqlmap.queryforlist<article> (Stmtid, ht); return result; }
Ibatis.net use Summary (iv)--IBatis call stored procedure