Stored procedures:
Use Base_passport Go Create proc Yhj_test @input_a int, @input_b int, @output_c int Out As Begin SELECT * from Config.city; Set @output_c = @input_a * @input_b; return @input_a + @input_b; End |
Mybats configuration:
<resultmap type= "Java.util.HashMap" id= "Resultmap" > <result column= "City_key" property= "Citykey" javatype= "Java.lang.Integer" jdbctype= "Integer"/> <result column= "Province_key" property= "Provincekey" javatype= "Java.lang.Integer" jdbctype= "Integer"/> <result column= "City_name" property= "CityName" javatype= "java.lang.String" jdbctype= "VARCHAR"/> </resultMap> <select id= "Testbyproc" statementtype= "callable" parametertype= "Java.util.HashMap" resultmap= "Resultmap" > <! [cdata[ {#{d,mode=out,jdbctype=integer}=call Dbo.yhj_test ( #{a,mode=in,jdbctype=integer}, #{b,mode=in,jdbctype=integer}, #{c,mode=out,jdbctype=integer} )} ]]> </select> |
Java code
map<string, object> parammap = new hashmap<string, object> (); Parammap.put ("A", 2); Parammap.put ("B", 3); List<city> citys = (list<city>) gettemplate (). SelectList (Getnamespaceandmethod ("TestByProc"), ParamMap) ; return citys; |
Through the above code we can get the corresponding result set, return parameters and output parameters. Where the return parameter and output parameters are placed in the incoming Parammap, the results are as follows:
C is the output parameter of the stored procedure, and D is the return parameter.
Things to be aware of:
1, the stored procedure parameters and names are independent, and only the order of the relationship
2, the stored procedure output parameters, can only be obtained through the incoming map
3. The result set returned by the stored procedure can be received directly with the returned map
4, the return result of the stored procedure need to use? =call procname (?,?) The first parameter receives, you need to specify the corresponding mode out type
5, the stored procedure corresponds to the data type is enumerated type, need to use uppercase, such as varchar