MyBatis Plus 里调用存储过程
mapper接口
public interface UserInfoMapper extends BaseMapper<UserInfo> { void countByType(String checkNo); }
sql xml
注意这里的存储过程是有入参,无返回值的
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.xxx.mapper.UserInfoMapper"> <!-- 调的数据库里的存储过程 --> <update id="countByType" parameterType="string" statementType="CALLABLE"> {call countByType(#{checkNo, mode=IN})} </update> </mapper>
存储过程创建语句
CREATE DEFINER=`xxxxx`@`` PROCEDURE `countByType`(in in_batch_number varchar(32)) BEGIN -- 定义变量 DECLARE var_batch_number VARCHAR(18); -- 批次号如果有传入则使用传入的,没有则使用生成的 IF in_batch_number is null THEN SET var_batch_number = date_format(DATE_SUB(now(), INTERVAL 1 DAY), '%Y%m%d'); ELSE SET var_batch_number = in_batch_number; END IF; -- 调用其它存储过程存储过程 call countByDate(var_batch_number); END