zoukankan      html  css  js  c++  java
  • mybatis调用mysql存储过程

    返回类似 select *from 的做法
    过程:
    create procedure selectAll()
    BEGIN
    select * from user;
    end

    xml配置:
    <select id="selectall" resultType="map" statementType="CALLABLE">
    {call selectAll()}
    </select>

    java配置:
    //service层调用
    List<Map<String, Object>> ss = accountMapper.selectall();
    //DAO调用
    public List<Map<String,Object>> selectall();

    Sql代码
    -- --------------------------------------------------------------------------------
    -- Routine DDL
    -- Note: comments before and after the routine body will not be 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) into @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) into @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调用传入MAP。获取通过MAP获取。
    1.1 mapper文件写法
    Xml代码
    <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调用写法
    Java代码
    @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");
    }

  • 相关阅读:
    题解 [CF891C] Envy
    题解 [BZOJ4710] 分特产
    题解 [BZOJ2159] Crash的文明世界
    题解 [BZOJ4144] Petrol
    #leetcode刷题之路1-两数之和
    week 7 文件操作与模板
    coursera 北京大学 程序设计与算法 专项课程 STL week8 list
    coursera 北京大学 程序设计与算法 专项课程 完美覆盖
    JSTL标签库不起作用的解决方案 .(转)
    javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext解决办法(转)
  • 原文地址:https://www.cnblogs.com/sanhuan/p/4205238.html
Copyright © 2011-2022 走看看