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. VC++判断是否连网

    在开发中,需要判断是否有网络连接,于是写了个函数,实现代码如下: //判断是否有网络连接 static BOOL DoHaveInternetConnection() { BOOL bRet = FA ...

  2. Android with Eclipse - Waiting for HOME ('android.process.acore') to be launched?

    mac机中使用命令行方式启动android sdk manager,有需要的朋友可以参考下. 相信使用mac机的用户做android开发都会有一个困惑,就是如何更新android sdk,或者说直接使 ...

  3. extSourceStat_7Day_Orders.php

    <?php /** Log文件格式2012/7/4 列号 字段含义 取值 ------------------------------------------------------------ ...

  4. tp集成支付宝担保支付

    现在的网站功能越来越全乎了,很多网站都需要做支付功能,而且很多大平台都提供了各式各样的api来扩充自己的用户和开发者.话说,这种使用大平台的api来做支付,无论是从成本上还是从开发效率上都是很好的选择 ...

  5. (转)php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法

    php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime. 下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日.上周.本月的起 ...

  6. win7 iis7.5 配置错误解决办法

    win7 iis7.5 配置HTTP 错误 404.3 在初次使用IIS7的时候经常遇到的一个错误解决办法1: 找到Visual Studio命令提示工具,运行aspnet_regiis.exe -i ...

  7. JMeter对Selenium自动化代码进行压测

    原文转载:http://www.blogjava.net/qileilove/archive/2014/06/05/414423.html 准备工作: 将文件selenium-server-stand ...

  8. 修改PYTHONPATH的一种方法(在Window平台和Ubuntu下都有效)

    1.显示PYTHONPATH 2.修改PYTHONPATH 通过PYTHONPATH 中的任何 .pth 文件来添加pythonpath.比如我想添加/home/aa这个路径到pythonpath里, ...

  9. JS 同源策略

    对于任何基于WEB的应用,最重要的就是安全性.JS中有各种安全检查以防止恶意脚本攻击你的机器,其中一些特定的安全手段在各种浏览器中都有采用.如:Mozilla有个完全独特的完全模型,涉及到了签署脚本和 ...

  10. 标准的最大margin问题

    standard large margin problem 分割线