Ibatis.Net 执行存储过程学习(八)
首先在数据库创建存储过程:
create proc [dbo].[usp_GetPersonById]
@Id int
as
begin
select Id,Name from Person where Id=@Id
end
XML映射文件中定义参数集合:
<parameterMaps>
<!--注意:parameterMap中的参数个数和顺序要和存储过程中的一致-->
<parameterMap id="GetPersonByIdProc">
<parameter property="Id" column="Id"/>
</parameterMap>
</parameterMaps>
然后定义操作:
<!--执行存储过程-->
<procedure id="usp_GetPersonById" parameterMap="GetPersonByIdProc" resultClass="PersonViewModel">
usp_GetPersonById
</procedure>
DAO层:
public PersonViewModel GetPersonByIdProc(Hashtable ht)
{
PersonViewModel p = mapper.QueryForObject<PersonViewModel>("usp_GetPersonById", ht);
return p;
}
Main调用:
static void Main(string[] args)
{
PersonDAO dao = new PersonDAO();
Hashtable ht = new Hashtable();
ht.Add("Id", );
PersonViewModel p = dao.GetPersonByIdProc(ht);
if (p != null)
Console.WriteLine(p.Id + p.Name); Console.ReadKey();
}
注意:Hashtable中的键值名称和参数集合中的property相对应,并且区分大小写。
执行带output输出参数的存储过程
修改下存储过程:
ALTER proc [dbo].[usp_GetPersonById]
@Id int,
@totalCount int output
as
begin
select Id,Name from Person where Id=@Id
set @totalCount=(select count(*) from Person)
end
XML映射文件中定义参数集合:
<parameterMaps>
<!--注意:parameterMap中的参数个数和顺序要和存储过程中的一致-->
<parameterMap id="GetPersonByIdProc">
<parameter property="Id" column="Id"/>
<parameter property="totalCount" column="totalCount" direction="Output"/>
</parameterMap>
</parameterMaps>
定义操作和DAO层不变:
<!--执行存储过程-->
<procedure id="usp_GetPersonById" parameterMap="GetPersonByIdProc" resultClass="PersonViewModel">
usp_GetPersonById
</procedure>
Main调用:
static void Main(string[] args)
{
int totalCount = ;
PersonDAO dao = new PersonDAO();
Hashtable ht = new Hashtable();
ht.Add("Id", );
ht.Add("totalCount", totalCount);
PersonViewModel p = dao.GetPersonByIdProc(ht);
if (p != null)
Console.WriteLine(p.Id + p.Name+" 共"+ ht["totalCount"] + "条数据"); Console.ReadKey();
}
参考:http://www.cnblogs.com/caoyc/category/873268.html
Ibatis.Net 执行存储过程学习(八)的更多相关文章
- MyCat 学习笔记 第十三篇.数据分片 之 通过HINT执行存储过程
1 环境说明 VM 模拟3台MYSQL 5.6 服务器 VM1 192.168.31.187:3307 VM2 192.168.31.212:3307 VM3 192.168.31.150: 330 ...
- Java中执行存储过程和函数(web基础学习笔记十四)
一.概述 如果想要执行存储过程,我们应该使用 CallableStatement 接口. CallableStatement 接口继承自PreparedStatement 接口.所以CallableS ...
- Mysql学习---使用Python执行存储过程
使用Python执行存储过程 使用Python执行存储过程[2部分]: 1.执行存储过程,获取存储过程的结果集 2.将返回值设置给了 @_存储过程名_序号 = #!/usr/bin/env pyt ...
- sqlserver学习2---java执行存储过程
一.存储过程 1.新增操作存储过程 --------------1.新建 增加学生的存储过程---------------------------- set IDENTITY_INSERT stude ...
- C#学习-执行存储过程
使用存储的优点 1.执行更快.直接写sql脚本会有个解析编译的过程. 2.修改方便.当业务改变时,只需要改存储过程,不需要修改C#代码 3.传递Sql脚本数据相对更小 缺点: 1.使用存储过程,数据库 ...
- Python Tutorial 学习(八)--Errors and Exceptions
Python Tutorial 学习(八)--Errors and Exceptions恢复 Errors and Exceptions 错误与异常 此前,我们还没有开始着眼于错误信息.不过如果你是一 ...
- mySql-数据库之存储过程学习总结
之前在工作中总是听别人提到存储过程,觉得是个很高深的东西,利用工作之余,看了下相关的知识,现将学习知识总结如下,希望可以为刚学习的人提供些许帮助. 开发环境:Navicat For Mysql. My ...
- SQL server 存储过程学习
一.定义变量--简单赋值 declare @a intset @a=5 print @a --使用select语句赋值 declare @user1 nvarchar(50) select @user ...
- Ibatis.Net 各种配置说明学习(二)
1.各个配置文件的配置说明 providers.config:指定数据库提供者,.Net版本等信息. xxxxx.xml:映射规则. SqlMap.config:大部分配置一般都在这里,如数据库连接等 ...
随机推荐
- 一本通1633【例 3】Sumdiv
1633:[例 3]Sumdiv 时间限制: 1000 ms 内存限制: 524288 KB [题目描述] 原题来自:Romania OI 2002 求 ABAB 的所有约数之和 mo ...
- jenkins迁移升级简述
1.迁移背景 原有jenkins版本为2.32.2,由于需要安装git parameter插件,插件安装失败,依赖暂时无法解决,因此决定升级jenkins版本,升级版本为2.121.2. 2.je ...
- Two Bases CodeForces - 602A (BigInteger c++long long也可以)
哇咔咔 卡函数的 标记一下 c++和java的进制转换函数都是1-36进制的 c++ long long暴力就过了... 自己写一个就好了 import java.math.BigInteger; i ...
- gym101350 c h m
C. Cheap Kangaroo time limit per test 1.0 s memory limit per test 256 MB input standard input output ...
- 使用Ubuntu的Crontab定时任务需要注意的地方
Ubuntu使用crontab定时任务 网上有很多教程,现在记录下我遇到的一些问题,需要注意的地方: 1.定时任务的日志存放路径 网上的说法:cron的日志存放在 /var/log/cron 里面 ...
- 【刷题】BZOJ 2734 [HNOI2012]集合选数
Description <集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所有满足以 下条件的子集:若 x 在该子集中,则 2x 和 3x 不能在该子集中 ...
- Java线程总结---第一天
线程和进程各自有什么区别和优劣: 进程是资源分配的最小单位,线程是程序执行的最小单位 进程有自己的独立地址空间,每启动一个进程,系统就会为它分配地址空间,建立数据表来维护代码段.堆栈段和数据段,这种操 ...
- 学习6__STM32--SPI外设之中断收发---
<目标> STM32双机 SPI中断收发通信 <描述> # STM32双机配置为一主一从模式 # 采用主机中断发送,从机中断接收 # 收发机制采用不间断收发(发送为空就发送,接 ...
- SpringBoot整合Swagger-ui
SpringBoot整合Swagger-ui 引入依赖 <dependency> <groupId>org.springframework.boot</groupId&g ...
- “Uncaught TypeError: string is not a function”
http://www.cnblogs.com/haitao-fan/archive/2013/11/08/3414678.html 今天在js中写了一个方法叫做search(),然后点击按钮的时候提示 ...