一 . 数据库中创建存储过程,并查看创建结果
1.创建存储过程
DROP procedure IF EXISTS net_procedure_request; DELIMITER $$ CREATE procedure net_procedure_request(in select_type varchar(99)) BEGIN IF select_type='0' THEN select client_ip,request_size_all,from_unixtime(start_time,'%Y年%m月%d日-%H时:%i分:%S秒') as startTime from net_table_request; ELSEIF select_type='1' THEN select client_ip,request_size_all,from_unixtime(start_time,'%Y年%m月%d日-%H时:%i分') as startTime from net_table_request; ELSEIF select_type='2' THEN select client_ip,request_size_all,from_unixtime(start_time,'%Y年%m月%d日-%H时') as startTime from net_table_request; END IF; END$$ DELIMITER ;
2.查看创建存储过程结果
show procedure status;
3.导出创建存储过程的语句
show create procedure net_procedure_request;
4.数据库调用存储过程
set @select_type='0'; call net_procedure_request(@select_type);
二 . MyBatis中调用存储过程
<select id="getInfo" statementType="CALLABLE" resultMap="infoResultMap" parameterType="java.util.HashMap"> {call net_procedure_request(#{select_type,mode=IN,jdbcType=VARCHAR},#{client_ip,mode=IN,jdbcType=VARCHAR})} </select>
注意:select标签中一定要加《statementType=“CALLABLE”》。