mybatis框架中动态SQL的编写
1.动态SQL:在SQL语句中加入流程控制。比如加入if,foreach等。
重点掌握if语句:
案例1:
<update id="updateItem" parameterType="com.gxa.bj.model.UserInfo">
update userinfo set
<if test="userName!=null">
userName = #{userName},
</if>
<if test="userPwd!=null">
userPwd = #{userPwd},
</if>
<if test= "userEmail!=null">
userEmail = #{userEmail},
</if>
<if test= "userAddress!=null">
userAddress = #{userAddress},
</if>
<if test= "regReason!=null">
regReason = #{regReason},
</if>
userId=#{userId} Where userId=#{userId}
</update>
案例2:
<select id="getList" parameterType="com.gxa.bj.model.UserInfo" resultType="com.gxa.bj.model.UserInfo">
Select * From userInfo Where 1=1
<if test="userName!=null">
And userName like #{userName}
</if>
<if test="userId>0">
And userId =#{userId}
</if>
<if test="userPwd!=null And userPwd!=''">
And userPwd like #{userPwd}
</if>
</select>
mybatis框架中动态SQL的编写的更多相关文章
- mybatis框架(5)---动态sql
那么,问题来了: 什么是动态SQL? 动态SQL有什么作用? 传统的使用JDBC的方法,相信大家在组合复杂的的SQL语句的时候,需要去拼接,稍不注意哪怕少了个空格,都会导致错误.Mybatis的动态S ...
- mybatis框架中 动态代理的问题
在配置文件时候 id唯一性 所以不允许重载 <select id=" querydemo" resultType="pojo"> sql 语句 ...
- 详解Java的MyBatis框架中SQL语句映射部分的编写
这篇文章主要介绍了Java的MyBatis框架中SQL语句映射部分的编写,文中分为resultMap和增删查改实现两个部分来讲解,需要的朋友可以参考下 1.resultMap SQL 映射XML 文件 ...
- MyBatis中动态SQL元素的使用
掌握MyBatis中动态SQL元素的使用 if choose(when,otherwise) trim where set foreach <SQL>和<include> 在应 ...
- Mybatis中动态SQL多条件查询
Mybatis中动态SQL多条件查询 mybatis中用于实现动态SQL的元素有: if:用if实现条件的选择,用于定义where的字句的条件. choose(when otherwise)相当于Ja ...
- Mybatis中动态SQL语句中的parameterType不同数据类型的用法
Mybatis中动态SQL语句中的parameterType不同数据类型的用法1. 简单数据类型, 此时#{id,jdbcType=INTEGER}中id可以取任意名字如#{a,jdbcType ...
- Mybatis框架中实现双向一对多关系映射
学习过Hibernate框架的伙伴们很容易就能简单的配置各种映射关系(Hibernate框架的映射关系在我的blogs中也有详细的讲解),但是在Mybatis框架中我们又如何去实现 一对多的关系映射呢 ...
- mybatis 详解------动态SQL
mybatis 详解------动态SQL 目录 1.动态SQL:if 语句 2.动态SQL:if+where 语句 3.动态SQL:if+set 语句 4.动态SQL:choose(when,o ...
- mybatis学习 十 动态 SQL
1. 根据方法传入的参数不同执行不同的 SQL 命令.称为动态 SQL, MyBatis 中动态 SQL 就是在 mapper.xml 中添加逻辑判断等. 2. <if>标签 <s ...
随机推荐
- 类似lol的友军视野怎么实现
https://github.com/kbengine/kbengine/issues/129 你们可以按这个思路自己先改一下 例如: 可将队友的AOI实体也同步到自己的客户端中. 可对某些特定类型的 ...
- Django web 进阶
.路由系统 .模板引擎 simple_tag .Form .Ajax请求 -简单数据 -复杂数据 内容: -作业 model xss.csrf(安全方面的内容) 分页(公共的模块) 内容复习和今日内容 ...
- table变色
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...
- java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data fr
Android中操作Sqlite遇到的错误:java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. ...
- JS,JQuery的扩展方法
转 http://blog.csdn.net/tuwen/article/details/11464693 //JS的扩展方法: 1 定义类静态方法扩展 2 定义类对象方法扩展 ...
- --查询nvarchar(max)的表和字段
--查询nvarchar(max)的表和字段 select 'insert into #tempTabelInfo select '''+d.name+''', '''+a.name+''', max ...
- iOS 利用for循环创建九宫格
// 利用for循环创建九宫格 - (void)createScratchableLatex{ // 总列数 ; // 每一格的尺寸 CGFloat cellW = (self.frame.size. ...
- spring-mybatis jar下载地址
http://central.maven.org/maven2/org/mybatis/mybatis-spring/1.3.0/
- 【Python全栈笔记】05 [模块二] 19 Oct 文件的操作
文件操作 一般步骤1. 文件打开 2. 文件操作 3. 文件关闭 1. 打开文件 使用open(文件名(绝对路径), 打开模式, 编码) 文件打开的模式有: r: 只读模式(默认) w: 只写模式 ...
- lua 学习笔记一
参考: http://www.kancloud.cn/digest/luanote/119924 1.基础概念 1.lua八种基本数据类型:nil.boolean.string.function.ta ...