mybatis框架(动态SQL语句)
2016-07-01 16:13
549 查看
1.实现动态的SQL语句
2.掌握的分页
3.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>
2.掌握的分页
3.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>
相关文章推荐
- Redis学习笔记(一)
- Redis--持久化
- Redis 请求应答模式和往返延时 Pipelining
- Redis主从复制
- mysql参数sql_log_bin
- Redis集群
- Redis Cluster 3.0搭建与使用
- 解决MySQL主从复制不一致的情况
- SQL把做个字段组合成一个字符串
- Redis源码解析(1)——源码目录介绍
- Golang 读取写入Etcd数据库
- 在多台服务器上简单实现Redis的数据主从复制
- DB2 create table报错-104 42601 SQL语句中遇到非法符号
- windowts系统下安装的mysql开启远程链接功能
- mongodb学习链接
- 数据库整理
- 详细讲解 centOS下 Redis安装及配置
- SQL语句跟部分执行顺序
- OpenJDK和Sun/OracleJDK 区别 与联系
- Oracle创建触发器详解及例子