ssm框架如何調(diào)用mysql存儲(chǔ)過程
1.建表
/* Navicat MySQL Data Transfer Source Server : localMysql Source Server Version : 50628 Source Host : 127.0.0.1:3306 Source Database : testmysql Target Server Type : MYSQL Target Server Version : 50628 File Encoding : 65001 Date: 2017-06-19 09:29:34 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for t_user -- ---------------------------- DROP TABLE IF EXISTS `t_user`; CREATE TABLE `t_user` ( `id` bigint(11) NOT NULL AUTO_INCREMENT, `user_name` varchar(255) DEFAULT NULL COMMENT '用戶名', `user_phone` varchar(20) DEFAULT NULL COMMENT '手機(jī)號(hào)', `user_email` varchar(255) DEFAULT NULL COMMENT '郵箱地址', `user_pwd` varchar(32) DEFAULT NULL COMMENT '加鹽后用戶密碼', `pwd_salt` varchar(6) DEFAULT NULL COMMENT 'MD5鹽', `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時(shí)間', `modify_time` datetime DEFAULT NULL COMMENT '最后修改時(shí)間', `is_delete` tinyint(4) DEFAULT NULL COMMENT '是否刪除,0-未刪除;1-已刪除', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='用戶登錄表'; -- ---------------------------- -- Records of t_user -- ---------------------------- INSERT INTO `t_user` VALUES ('1', '子了a', '13285250574', '1045221654@qq.com', '05126a423a9379d529e4ee61a212fa55', 'KJUYT5', '2016-07-15 23:38:56', '2016-07-15 23:39:09', '0'); INSERT INTO `t_user` VALUES ('2', 'bbbb', '159852505743', '1198224554@qq.com', '98bd3a1bebde01ad363d3c5a0d1e56da', '656JHU', '2016-07-15 23:39:01', '2016-07-15 23:39:13', '0'); INSERT INTO `t_user` VALUES ('3', '王尼瑪', '13685250574', '1256221654@qq.com', '5470db9b63c354f6c8d628b80ae2f3c3', '89UIKQ', '2016-07-15 23:39:05', '2016-07-15 23:39:16', '0');
2.創(chuàng)建存儲(chǔ)過程
CREATE DEFINER=`root`@`localhost` PROCEDURE `UPDATE_USER`(IN `in_id` integer,IN `in_user_name` varchar(20),OUT `out_user_phone` varchar(20)) BEGIN update t_user set user_name = in_user_name WHERE t_user.id = in_id; select user_phone INTO out_user_phone from t_user where id = in_id;
3.service調(diào)用
package cn.demo.service; import cn.demo.dao.AccountDao; import cn.demo.model.Account; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.HashMap; import java.util.List; import java.util.Map; import static junit.framework.TestCase.assertEquals; /** * Created by Administrator on 2017/3/22. */ @RunWith(SpringJUnit4ClassRunner.class) //這個(gè)是用來加載寫好的配置文件,傳入的值是數(shù)組形式多個(gè)配置文件如下 {"····","·······"} @ContextConfiguration({"classpath:spring/spring-dao-config.xml"}) public class AccountServiceTest { @Autowired private AccountDao accountDao; // @Test public void getAllAccount() throws Exception { List<Account> accountList = accountDao.getAllAccount(); System.out.println("accountList=" + accountList.toString()); } @Test public void testGetNamesAndItems() { Map<String, Object> parms = new HashMap<String, Object>(); parms.put("in_id", 1); parms.put("in_user_name", "子了"); parms.put("out_user_phone", new String()); accountDao.updateUser(parms); assertEquals("13285250574", parms.get("out_user_phone")); } }
4.dao層
package cn.demo.dao; /** * Created by chengcheng on 2017/6/2 0002. */ import cn.demo.model.Account; import org.springframework.stereotype.Repository; import java.util.List; import java.util.Map; /** * Created by Administrator on 2017/3/22. */ @Repository public interface AccountDao { String updateUser(Map<String, Object> parms); }
5.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="cn.demo.dao.AccountDao"> <select id ="updateUser" parameterType= "map" statementType="CALLABLE" > <!--注明statementType="CALLABLE"表示調(diào)用存儲(chǔ)過程--> {call UPDATE_USER( #{in_id, jdbcType=INTEGER, mode=IN}, #{in_user_name, jdbcType= VARCHAR, mode=IN}, #{out_user_phone, mode=OUT, jdbcType= VARCHAR} )} <!--傳入傳出參數(shù)要注明mode=IN/OUT 并要注明jdbcType(在網(wǎng)上可以查詢mybatis支持哪些jdbcType類型),返回參數(shù)要注明對(duì)應(yīng)的resultMap--> </select > </mapper>
6.接下來運(yùn)行junit就可以了
如果是在直接在應(yīng)用中使用,把juinit內(nèi)容直接放入service就可以了
到此這篇關(guān)于ssm框架調(diào)用mysql存儲(chǔ)過程的文章就介紹到這了,更多相關(guān)ssm框架mysql存儲(chǔ)過程內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
騰訊面試:一條SQL語句執(zhí)行得很慢的原因有哪些?---不看后悔系列(推薦)
這篇文章主要介紹了SQL語句執(zhí)行慢的原因,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04解決MySQL登錄報(bào)錯(cuò)1045-Access?denied?for?user?'root'@
這篇文章主要給大家介紹了關(guān)于解決MySQL登錄報(bào)錯(cuò)1045-Access?denied?for?user?‘root‘@‘‘(using?password:YES)的相關(guān)資料,文中一步步將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07Mysql 數(shù)據(jù)庫死鎖過程分析(select for update)
最近有項(xiàng)目需求,需要保證多臺(tái)機(jī)器不拿到相同的數(shù)據(jù),后來發(fā)現(xiàn)Mysql查詢語句使用select.. for update經(jīng)常導(dǎo)致數(shù)據(jù)庫死鎖問題,下面小編給大家介紹mysql 數(shù)據(jù)庫死鎖過程分析(select for update),對(duì)mysql數(shù)據(jù)庫死鎖問題感興趣的朋友一起學(xué)習(xí)吧2015-12-12MySQL數(shù)據(jù)庫誤刪恢復(fù)的超詳細(xì)教程
MySQL誤刪數(shù)據(jù)庫,造成了數(shù)據(jù)的丟失,這是非常尷尬的,但是有許多方案可以用來嘗試恢復(fù)丟失的數(shù)據(jù)庫,這篇文章主要給大家介紹了關(guān)于MySQL數(shù)據(jù)庫誤刪恢復(fù)的超詳細(xì)教程,需要的朋友可以參考下2024-03-03Mysql實(shí)現(xiàn)模糊查詢的兩種方式(like子句?、正則表達(dá)式)
通配符是一種特殊語句,主要用來模糊查詢,下面這篇文章主要給大家介紹了關(guān)于給Mysql實(shí)現(xiàn)模糊查詢的兩種方式,分別是like子句?、正則表達(dá)式,需要的朋友可以參考下2022-09-09