sqlMap:
<select id="proc_name" statementType="CALLABLE" parameterType="java.util.HashMap" resultType="java.lang.Integer"> { call proc_name( #{userId,mode=IN,jdbcType=INTEGER}, #{auditPoolId,mode=OUT,jdbcType=VARCHAR} ) } </select>
存储过程:
DELIMITER $$ CREATE PROCEDURE `databaseName`.`proc_name` (IN userId BIGINT(20), OUT auditPoolId INT) BEGIN DECLARE v_totalCount INT ; DECLARE v_borrowId INT ; -- 我的数量 SELECT COUNT(*) totalCount FROM fk_audit_pool t WHERE t.status = '1' AND t.checkout_user_id = userId INTO v_totalCount ; IF v_totalCount < 10 THEN -- 获取最老的一条数据 SELECT id, t.xd_borrow_form_id FROM fk_audit_pool t WHERE t.xd_borrow_form_id = (SELECT MAX(t.xd_borrow_form_id) FROM fk_audit_pool t WHERE t.status = '0') INTO auditPoolId,v_borrowId ; -- 修改状态 UPDATE fk_audit_pool t SET t.status = '1', t.checkout_user_id = userId, t.checkout_time = SYSDATE() WHERE t.xd_borrow_form_id = v_borrowId ; END IF ; END $$ DELIMITER ;
调用:
Map<String, Object> getOneMap = new HashMap<String, Object>();
getOneMap.put("userId", sysUser.getUserId());
dao.getOne("proc_name",paraMap); Integer id = (Integer) paraMap.get("auditPoolId");//存储过程的output参数,只能通过传入的map获取