接口测试从零开始5_教你如何使用ibatis
来源:互联网 发布:开源商城cms 编辑:程序博客网 时间:2024/04/30 15:36
1. 创建pojo类
public classPingJia
2. 创建Dao接口
publicinterfaceIPingJiaDao
3. 使用ibatis编写实现类
1. 通过pom依赖引入ibatis包
<dependency>
<groupId>com.ibatis</groupId>
<artifactId>ibatis</artifactId>
<version>2.3.4.726</version>
</dependency>
2. 编写实现类,引入ibatisSqlMapClient和Resource
importcom.ibatis.common.resources.Resources;
importcom.ibatis.sqlmap.client.SqlMapClient;
importcom.ibatis.sqlmap.client.SqlMapClientBuilder;
3. 配置POJO类的IBatis配置文件pingjia.ibatis.xm
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsqlMapPUBLIC"-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMapnamespace="PingJiaDao">
<!--命名空间,在此空间外要引用此空间的元素,则需要加上命名空间名-->
<typeAliasalias="pingJia"type="com.koubei.testlearnning.pojo.PingJia"/>
<!--实体别名, 如果有用到全名的地方,可以用别名代替,受命名空间约束-->
<resultMapclass="com.koubei.testlearnning.pojo.PingJia"id="PingJia">
<resultcolumn="pingjiaid"property="pingJiaId"/>
<resultcolumn="pingjiacontent"property="pingJiaContent"/>
<resultcolumn="storeid"property="storeId"/>
<resultcolumn="pingjiatype"property="pingJiaType"/>
<resultcolumn="pingjiadate"property="pingJiaDate"/>
</resultMap>
<!--结果集映射,-->
<deleteid="delete"parameterClass="java.lang.String">
<!--删除操作-->
delete frompingjiawherepingjiaid=#pingJiaId#
</delete>
<insertid="insert"parameterClass="pingJia">
<!--插入操作, 对于自增主键的表,插入可以不配置插入的主键列,否则是必须的-->
insert
intopingjia(pingjiaid,pingjiacontent,storeid,
pingjiatype,pingjiadate)
values(#pingJiaId#, #pingJiaContent#, #storeId#, #pingJiaType#,#pingJiaDate#)
</insert>
<updateid="update">
<!--更新操作-->
update task_info
<dynamicprepend="set">
<!--动态sql:prepend表示链接关键字,property表示属性值-->
<isNotNullprepend=" , "property="pingJiaContent">
pingjiacontent=
#excutePerson#
</isNotNull>
<isNotNullprepend=" , "property="storeid">
storeid=#storeId#
</isNotNull>
<isNotNullprepend=" , "property="pingJiaType">
pingjiatype
=#pingJiaType#
</isNotNull>
<isNotNullprepend=" , "property="pingjiadate">
pingjiadate
=#pingJiaDate#
</isNotNull>
</dynamic>
wherepingjiaid=#pingJiaId#
</update>
<selectid="getPingJiaList"parameterClass="java.lang.String"resultMap="PingJia">
<!--查询操作,插入语句入参通过parameterClass="类别名"来设定,可以设定类别名,也可以设定为map,
也可以设定为iBatis支持的原生类型(比如string、int、long等, map是最强大的入参方式,任何入参方式
都可以转换为这种入参方式,因为iBatis仅接受一个入参,当几个参数分布在不同对象中的时候,将这些对象
的属性(或者对象本身put)到map中,然后一次传递给sql语句-->
sselect* frompingjiawhere storeId = #storeId#
</select>
<selectid="getGoodPingNum"parameterClass="java.lang.String">
sselectcount(1) frompingjiawhere storeId = #storeId# andpingjiatype=1
</select>
<selectid="getPingJiaNum"parameterClass="java.lang.String">
sselectcount(1) frompingjiawhere storeId = #storeId#
</select>
</sqlMap>
察看教你如何使用ibatis2
原文:http://www.51testing.com/?uid-128005-action-viewspace-itemid-804272
- 接口测试从零开始5_教你如何使用ibatis
- 接口测试从零开始5_教你如何使用ibatis2
- 接口测试从零开始系列1_如何针对接口方法设计测试用例
- 接口测试从零开始系列_mock技术使用
- 接口测试从零开始系列7_Maven使用
- 接口测试从零开始系列_mock技术使用
- 接口测试从零开始系列_mock技术使用
- 接口测试从零开始系列6_简简单单Spring1
- 接口测试从零开始系列6_简简单单Spring2
- 从入门到精通,教你如何使用eoLinker成为接口测试高手
- 教你如何使用支付宝接口
- 从零开始:教你如何训练神经网络
- 手把手教你如何使用IOMETER测试工具测试存储
- 手把手教你如何使用iometer测试工具测试存储
- 教你如何抓接口
- 教你如何使用JMock来实现孤立测试
- 教你如何使用JMock来实现孤立测试
- 接口测试从零开始2------接口测试的全过程2
- [Accessibility] Missing contentDescription attribute on image
- yii 获取 url action的名字
- 接口测试从零开始系列4_junit断言介绍2
- dhcpcd的静态IP配置方法
- 接口测试从零开始系列4_junit断言介绍3
- 接口测试从零开始5_教你如何使用ibatis
- 设计模式-快餐简解-【代理模式】
- 更新证书错误Code Sign error: Provisioning profile ‘XXXX'can't be found
- 关于checkbox你不得不注意的事情
- splint 编译安装
- web.xml的执行操作
- 接口测试从零开始5_教你如何使用ibatis2
- java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
- 接口测试从零开始系列6_简简单单Spring1