SSM环境下调用mysql存储过程

2020-01-09  本文已影响0人  Mr_J316

创建存储过程

CREATE PROCEDURE `sp_name`(IN age VARCHAR(30),OUT num INTEGER)
BEGIN
SELECT * FROM sys_user where sys_user.age > age;
SELECT count(*) into num FROM sys_user;
END

mapper

<select id="selectByAge" statementType="CALLABLE" parameterType="map" resultType="SysUser">
    {call sp_name( #{age,mode=IN,jdbcType=VARCHAR}, #{num,mode=OUT,jdbcType=INTEGER} )}
</select>

dao

List<SysUser> selectByAge( Map<String,Object> map );

service

public void findByAge() {
    //参数集合
    Map<String, Object> paramMap = new HashMap<>();
    //入参
    paramMap.put("age", "18");
    //出参,可以不写(如果写,值随意填)
    paramMap.put("num", 1);
    
    List<SysUser> users = baseMapper.selectByAge( map );
    int num = paramMap.get("num");
}
上一篇 下一篇

猜你喜欢

热点阅读