ibatas的一些实例及解释
Student.xml : <?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<!-- 通过typeAlias使得我们在下面使用Student实体类的时候不需要写包名 -->
<typeAliasalias="Student"type="com.iflytek.entity.Student"/>
<!-- 这样以后改了sql,就不需要去改java代码了 -->
<!-- id表示select里的sql语句,resultClass表示返回结果的类型 -->
<selectid="selectAllStudent"resultClass="Student">
select * from
tbl_student
</select>
<!-- parameterClass表示参数的内容 -->
<!-- #表示这是一个外部调用的需要传进的参数,可以理解为占位符 -->
<selectid="selectStudentById"parameterClass="int"resultClass="Student">
select * from tbl_student where id=#id#
</select>
<!-- 注意这里的resultClass类型,使用Student类型取决于queryForList还是queryForObject -->
<selectid="selectStudentByName"parameterClass="String"
resultClass="Student">
select name,birth,score from tbl_student where name like
'%$name$%'
</select>
<insertid="addStudent"parameterClass="Student">
insert into
tbl_student(name,birth,score) values
(#name#,#birth#,#score#)
<selectKeyresultClass="int"keyProperty="id">
select @@identity as inserted
<!-- 这里需要说明一下不同的数据库主键的生成,对各自的数据库有不同的方式: -->
<!-- mysql:SELECT LAST_INSERT_ID() AS VALUE -->
<!-- mssql:select @@IDENTITY as value -->
<!-- oracle:SELECT STOCKIDSEQUENCE.NEXTVAL AS VALUE FROM DUAL -->
<!-- 还有一点需要注意的是不同的数据库生产商生成主键的方式不一样,有些是预先生成 (pre-generate)主键的,如Oracle和PostgreSQL。
有些是事后生成(post-generate)主键的,如MySQL和SQL Server 所以如果是Oracle数据库,则需要将selectKey写在insert之前 -->
</selectKey>
</insert>
<deleteid="deleteStudentById"parameterClass="int">
<!-- #id#里的id可以随意取,但是上面的insert则会有影响,因为上面的name会从Student里的属性里去查找 -->
<!-- 我们也可以这样理解,如果有#占位符,则ibatis会调用parameterClass里的属性去赋值 -->
delete from tbl_student where id=#id#
</delete>
<updateid="updateStudent"parameterClass="Student">
update tbl_student set
name=#name#,birth=#birth#,score=#score# where id=#id#
</update>
</sqlMap>
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap>
<typeAlias alias="userLotteryInfoDO" type="com.taobao.chest.task.freeorder.dataobject.UserLotteryInfoDO"/> <resultMap id="userLotteryResultMap" class="userLotteryInfoDO">
<result property="id" column="id"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
<result property="userId" column="user_id"/>
<result property="activityId" column="activity_id"/>
<result property="umpActivityId" column="ump_activity_id"/>
<result property="win" column="win"/>
<result property="message" column="message"/>
<result property="lotteryTime" column="lottery_time"/>
<result property="orderId" column="order_id"/>
</resultMap> <sql id="user.lottery.info.selector">
<![CDATA[
select id,activity_id,win,ump_activity_id,user_id,order_id,gmt_create,gmt_modified,lottery_time,message
from user_lottery_info
]]>
</sql> <sql id="user.lottery.info.query_segment">
<dynamic prepend="where">
<isNotNull prepend=" and " property="id"><![CDATA[id=#id#]]></isNotNull>
<isNotNull prepend=" and " property="userId"><![CDATA[user_id=#userId#]]></isNotNull>
<isNotNull prepend=" and " property="orderId"><![CDATA[order_id=#orderId#]]></isNotNull>
<isNotNull prepend=" and " property="activityId"><![CDATA[activity_id=#activityId#]]></isNotNull>
<isNotNull prepend=" and " property="umpActivityId"><![CDATA[ump_activity_id=#umpActivityId#]]></isNotNull>
</dynamic>
</sql> <!-- insert into 基本语句 -->
<insert id="user.lottery.info.insert" parameterClass="userLotteryInfoDO">
insert into user_lottery_info(gmt_create,gmt_modified,user_id,activity_id,ump_activity_id,win,message,lottery_time,order_id)
values(now(),now(),#userId#,#activityId#,#umpActivityId#,#win#,#message#,now(),#orderId#)
<selectKey keyProperty="id" resultClass="long">
select LAST_INSERT_ID()
</selectKey>
</insert> <!--更新-->
<update id="user.lottery.info.update" parameterClass="userLotteryInfoDO">
update user_lottery_info set win = #win#,message = #message#,gmt_modified=now() where order_id=#orderId#
</update> <select id="user.lottery.info.select.by.id" parameterClass="long" resultMap="userLotteryResultMap">
select id,activity_id,win,ump_activity_id,user_id,order_id,gmt_create,gmt_modified,lottery_time,message
from user_lottery_info WHERE order_id=#orderId#
</select> <select id="user.lottery.info.query" parameterClass="userLotteryInfoDO" resultMap="userLotteryResultMap">
<include refid="user.lottery.info.selector"/>
<include refid="user.lottery.info.query_segment"/>
</select> <!--6.12 新增加根据userId查询的sql语句-->
<select id="user.lottery.info.select.by.user.id" parameterClass="long" resultMap="userLotteryResultMap">
<![CDATA[
select id,activity_id,win,ump_activity_id,user_id,order_id,gmt_create,gmt_modified,lottery_time,message
from user_lottery_info
where user_id = #userId#
]]>
</select>
</sqlMap>
这里面有sql语句有关键词select,insert等,类型比较多
ibatas的一些实例及解释的更多相关文章
- 免费的HTML5连载来了《HTML5网页开发实例具体解释》连载(六)媒体查询
响应式设计的还有一个重要技术手段是媒体查询.假设仅仅是简单的设计一个流式布局系统,那么能够保证每一个网格按比例的放大和缩小,但有可能会使得在小屏幕下(如手机设备)网格太小而严重影响阅读,这种设计称不上 ...
- 感谢各位亲们的大力支持,免费的HTML5学习课程《HTML5网页开发实例具体解释》连载已经结束了!
感谢各位亲们的大力支持,免费的HTML5学习课程<HTML5网页开发实例具体解释>连载已经结束了. 有兴趣的读者能够看我的博客,也能够看以下的链接逐个学习: 当里个当.免费的HTML5连 ...
- 《HTML 5网页开发实例具体解释》样章、内容简单介绍、前言
http://spu.jd.com/1167757597.html http://product.dangdang.com/23484942.html 样章 http://download.csdn. ...
- Linux守护进程简单介绍和实例具体解释
Linux守护进程简单介绍和实例具体解释 简单介绍 守护进程(Daemon)是执行在后台的一种特殊进程.它独立于控制终端而且周期性地执行某种任务或等待处理某些发生的事件.守护进程是一种非常实用的进程. ...
- Swift难点-继承中的构造规则实例具体解释
关于继承中的构造规则是一个难点. 假设有问题,请留言问我. 我的Swift新手教程专栏 http://blog.csdn.net/column/details/swfitexperience.html ...
- Oracle之Check约束实例具体解释
Oracle | PL/SQL Check约束使用方法具体解释 1. 目标 实例解说在Oracle中怎样使用CHECK约束(创建.启用.禁用和删除) 2. 什么是Check约束? CHECK约束指在表 ...
- Linux C 单链表 读取文件 并排序 实例并解释
C的指针挺头疼的,先看一个例子: 给指针赋值和通过指针进行赋值这两种操作的差别确实让人费解.谨记区分的重要方法是:如果对左操作数进行解引用,则修改的是指针所指对象的值: 如果没有使用解引用操作, ...
- 《HTML 5网页开发实例具体解释》文件夹
第一篇 从宏观上认识HTML 5 讲述了HTML 5引发的Web革命.HTML 5的总体特性.HTML 5相关概念和框架和开发环境搭建. 第1章 HTML 5引发的Web革命 1.1 你是不是真的 ...
- boost asio异步读写网络聊天程序client 实例具体解释
boost官方文档中聊天程序实例解说 数据包格式chat_message.hpp <pre name="code" class="cpp">< ...
随机推荐
- HTML5 Canvas 2D绘图
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/ShiJiaqi. http://www.cnblogs.com/shijiaqi1066/p/4851774. ...
- Socket 错误一览表
出现网络联机错误Socket error #11001 表示您的计算机无法连上服务器,请检查您的Proxy设定以及Proxy相关账号,或暂时取消您防毒软件的「个人防火墙」. · 出现网络联机错误Soc ...
- declare-styleable:自定义控件的属性
http://www.cnblogs.com/jisheng/archive/2013/01/10/2854891.html 在使用过程中, 1 TypedArray a = getContext() ...
- 关于HMTL -[HTML5]
前言: 为什么学习它?(HTML5) 会不会HTML5,其实并不会影响我的开发效率,我觉得终究还是跟个人性格有关,我喜欢前沿的东西.这就好比我大学里学的计算机,但我仍然会去看一些跟专业不相关的书籍一样 ...
- oracle 权限管理
系统权限 系统权限需要授予者有进行系统级活动的能力,如连接数据库,更改用户会话.建立表或建立用户等等.你可以在数据字典视图SYSTEM_PRIVILEGE_MAP上获得完整的系统权限.对象权限和系统权 ...
- UITabBar-UITabBarItem图片的背景颜色属性和文字的颜色大小设置
UITabBarItem设置的图片选中状态下默认的是蓝色,如何改变它的颜色为图片自带的颜色呢? typedef NS_ENUM(NSInteger, UIImageRenderingMode) { / ...
- 快速消除IOS 版本升级带来的警告
开发中我们经常会遇到这样的情况,我们在IOS 6.0开发的程序,当出现IOS 7.0 或者IOS8.0的时候,我们代码中得某些方法苹果已经不推荐使用了,建议我们改用新的方法.如果我们不更新方法,则会出 ...
- javascript 浏览器执行断点
在javascript代码里面有个语句可以让浏览器执行到这里的时候触发断点,这个命令就是 debugger 很好用
- 菜鸟日记之JSP二 内置对象的理解
·最近学习JSP了,对编程和网络又有了一些理解.无论是现实中人与人的交流,还是网络世界的接触,都是在相互表达自己的意思让别人知道,并理解对方的信息.然后我们知道的事情不断的变多,会又交杂出新的内容,不 ...
- Linux 权限基础说明
1 权限位说明 Linux文件或目录的权限位是由个9个权限位来控制的,每三位为一组,它们分别是文件属主(owner/user)读.写.执行,用户组(Group)的读.写.执行以及(Other)其他 ...