一 . 數據庫中創建存儲過程,並查看創建結果
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”》。
