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的一些实例及解释的更多相关文章

  1. 免费的HTML5连载来了《HTML5网页开发实例具体解释》连载(六)媒体查询

    响应式设计的还有一个重要技术手段是媒体查询.假设仅仅是简单的设计一个流式布局系统,那么能够保证每一个网格按比例的放大和缩小,但有可能会使得在小屏幕下(如手机设备)网格太小而严重影响阅读,这种设计称不上 ...

  2. 感谢各位亲们的大力支持,免费的HTML5学习课程《HTML5网页开发实例具体解释》连载已经结束了!

    感谢各位亲们的大力支持,免费的HTML5学习课程<HTML5网页开发实例具体解释>连载已经结束了.  有兴趣的读者能够看我的博客,也能够看以下的链接逐个学习: 当里个当.免费的HTML5连 ...

  3. 《HTML 5网页开发实例具体解释》样章、内容简单介绍、前言

    http://spu.jd.com/1167757597.html http://product.dangdang.com/23484942.html 样章 http://download.csdn. ...

  4. Linux守护进程简单介绍和实例具体解释

    Linux守护进程简单介绍和实例具体解释 简单介绍 守护进程(Daemon)是执行在后台的一种特殊进程.它独立于控制终端而且周期性地执行某种任务或等待处理某些发生的事件.守护进程是一种非常实用的进程. ...

  5. Swift难点-继承中的构造规则实例具体解释

    关于继承中的构造规则是一个难点. 假设有问题,请留言问我. 我的Swift新手教程专栏 http://blog.csdn.net/column/details/swfitexperience.html ...

  6. Oracle之Check约束实例具体解释

    Oracle | PL/SQL Check约束使用方法具体解释 1. 目标 实例解说在Oracle中怎样使用CHECK约束(创建.启用.禁用和删除) 2. 什么是Check约束? CHECK约束指在表 ...

  7. Linux C 单链表 读取文件 并排序 实例并解释

    C的指针挺头疼的,先看一个例子: 给指针赋值和通过指针进行赋值这两种操作的差别确实让人费解.谨记区分的重要方法是:如果对左操作数进行解引用,则修改的是指针所指对象的值:    如果没有使用解引用操作, ...

  8. 《HTML 5网页开发实例具体解释》文件夹

    第一篇  从宏观上认识HTML 5 讲述了HTML 5引发的Web革命.HTML 5的总体特性.HTML 5相关概念和框架和开发环境搭建. 第1章 HTML 5引发的Web革命 1.1  你是不是真的 ...

  9. boost asio异步读写网络聊天程序client 实例具体解释

    boost官方文档中聊天程序实例解说 数据包格式chat_message.hpp <pre name="code" class="cpp">< ...

随机推荐

  1. CentOS7上GitLab的使用

    生成SSH Keys 生成root账号的ssh key # ssh-keygen -t rsa -C "admin@example.com" 显示pub key的值 # cat ~ ...

  2. RMQ问题与ST算法

    RMQ(Range Minimum/Maximum Query)问题是求区间最值问题. 对于长度为 n 的数组 A,进行若干次查询,对于区间 [L,R] 返回数组A中下标在 [L,R] 中的最小(大) ...

  3. 使用Github建立个人博客

    总的说来 这个当有node.js 和gitbub的账号后,搭建一个自己的博客,想想还是挺美的事! 由于要把整个流程说清楚 估计lz还没这个实力,所以都是继承前辈们的经验,自己再添加一点遇到的问题和解决 ...

  4. JDK和JVM

    JDK: JDK包含的基本组件包括: javac – 编译器,将源程序转成字节码 jar – 打包工具,将相关的类文件打包成一个文件 javadoc – 文档生成器,从源码注释中提取文档 jdb – ...

  5. PHP 数组转字符串,与字符串转数组

    implode 使用一个字符串将数组变成字符串 <?php $array = array('lastname', 'email', 'phone'); $comma_separated = im ...

  6. Repeater为空时显示“暂无数据”,很方便实用方法

    Repeater为空时显示“暂无数据”,很方便实用方法 <FooterTemplate>   <asp:Label ID="lblEmptyZP" Text=&q ...

  7. [Mime] MimeHeaders--MimeHeader帮助类 (转载)

    点击下载 MimeHeaders.rar 这个类是关于Mime的Headers类看下面代码吧 /// <summary> /// 类说明:Assistant /// 编 码 人:苏飞 // ...

  8. Chart图形 [GDI+] OWCChart统计图的封装类 (转载)

    点击下载 OWCChart.zip 利用OWC11进行作统计图的封装类. /// <summary> /// 类说明:进行作统计图的封装类 /// 联系方式:361983679 /// 更 ...

  9. Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException

    异常Log: Error:Execution failed for task ‘:app:dexDebug’. > com.android.ide.common.process.ProcessE ...

  10. js - SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data jquery-1.9.1.min.js:3:4315

    FF中时不时报这个错, 就近段做项目来看,  一般是我通过 jquery获取form中的参数(或直接获取参数,并通过ajax进行异步请求的时候,如果有错,就抱该错误! 而对应的, 如果在 Google ...