MyBatis calling the MySQL stored procedure

Source: Internet
Author: User

Return to the practice similar to select *from
Process:
CREATE PROCEDURE SelectAll ()
BEGIN
select * from user;
End

XML configuration:
<select id= "SelectAll" resulttype= "map" statementtype= "callable" >
{Call SelectAll ()}
</select>

Java configuration:
Service Layer Invocation
list<map<string, object>> ss = Accountmapper.selectall ();
DAO calls
Public list<map<string,object>> SelectAll ();

SQL code
-- --------------------------------------------------------------------------------
--Routine DDL
--note:comments before and after the routine body is not being stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE definer= ' root ' @ ' localhost ' PROCEDURE ' selectcount ' (
in Pcsid int,
in Drid int,
in Partnerid int,
in CustomerId int,
Out Pcscount int,
Out Drcount int

)
BEGIN

Select COUNT (md.id) to @pcsC from Mdm_device MD
Left join mdm_device_security mds on mds.device_id = Md.id
where mds.device_rooted = Pcsid
and md.partner_id = Partnerid and md.customer_id = customerId;
Set pcscount = @pcsC;


Select COUNT (md.id) to @drC from Mdm_device MD
where md.managed_status = Drid and Date_sub (Curdate (), INTERVAL 7 day) <= DATE (md.un_manage_date)
and md.partner_id = Partnerid and md.customer_id = customerId;
Set drcount = @drC;



END


1.java call incoming map. Get via map.
1.1 Mapper File notation
XML code
<parametermap type= "Map" id= "Homevo" >
<parameter property= "Pcsid" jdbctype= "INTEGER" mode= "in"/>
<parameter property= "Drid" jdbctype= "INTEGER" mode= "in"/>
<parameter property= "Partnerid" jdbctype= "INTEGER" mode= "in"/>
<parameter property= "CustomerId" jdbctype= "INTEGER" mode= "in"/>
<parameter property= "Pcscount" jdbctype= "INTEGER" mode= "Out"/>
<parameter property= "Drcount" jdbctype= "INTEGER" mode= "Out"/>
</parameterMap>
<select id= "Selectforhome" parametermap= "Homevo"
Statementtype= "Callable" >
{Call SelectCount (
?,?,?,?,?,?
)}
</select>
1.2 Java call notation
Java code
@Override
Public Stringselecthomecount (Homevo home) throws Exception {
map<string, object> map = new hashmap<string, object> ();
Map.put ("Pscid", 0);
Map.put ("Drid", 1);
Map.put ("Partnerid", 25);
Map.put ("CustomerId", 50);
Map.put ("Isolation", 1);
SelectOne ("Mapper.selectforhome", map);
System.out.println (Map.get ("Pcscount"));

Return Map.get ("Drcount");
}

MyBatis calling the MySQL stored procedure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.