16Mybatis_动态sql_if判断
mybatis的核心就是动态sql.
什么是动态sql:对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接、组装。
这篇文章讲解sql中的if语句。它可以对查询条件进行判断,如果输入参数不为空才进行查询条件的拼接。这篇文章的核心就是下面的这段代码。
<!--
<where></where>相当于sql语句中的where关键字。
这个标签还有一个功能就是自动会去掉第一个and.,比如下面两句sql代码,如果第一个满足的那么就会去掉and这个关键字。 -->
<where>
<if test="userCustom!=null">
<if test="userCustom.sex!=null and userCustom.sex!=''">
and user.sex= #{userCustom.sex}
</if>
<if test="userCustom.username!=null and userCustom.username!=''" > and user.username=#{userCustom.username}
</if> </if> </where>
下面给出u具体案例:
案例代码结构如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASkAAAGgCAIAAAB5RAbFAAAgAElEQVR4nO2d+18T197v83ecH8/rHM9zHvuc/XSrSNNdt9u7fbq1uttdra2i7mYXjNVHqSIiFAUMeItFq+IF5S4C3iNekHpBFFHrBaQJiCQoSC5yZwDdc36YZLJmZq3JhSSTmXzfr/XqKzNZa2aFzttZmcz6jIoOFVu3Z/e+rqJ7bmLK+6H3o4Nv3/a0W3unb8j3bnsGjUqtN/ndHZNerdIY/Gs3lv0CgBNVyPa0MWUf7biKLzS9ZPtpmqbD1T1/RQUAMoF0r7q6WqfTkd5dn3SU7jqLL/96P31D/uX6lozi28t3nvNub+AeIG8C5l5VVdX48ePHjRtHqrAq/gT9qogp7y2FV08X/JRWsmZ9/pr1+Y3PX52rNU5dnzcrofBe06uKs4+EzU16tcoJY4FBo1Lr9RrOOud6Jy41OTVdKxmd3JXdG+DvyV1HpdabEA0FXQIAHwiMe4x4ixYtEnHvW81xuu0I3XZkyHh0y9aS7DMNZ9veM+WC+b2d+hdTrfHN0D/XlfMbY048Bg17zLu/g6EnQ7YNtiYjjmubBo27hsa1AXQlRziNAd8lAPCBALjHird48WIR9+7eb+szXXE8OD5sb64zvi19Piwsh2/Zvos3WF71CFozJx90kM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AMAaQD3AEAawD0AkAZwDwCkAdwDAGkA9wBAGsA9AJAGcA8ApAHcAwBp+P8r21mBllEpPQAAAABJRU5ErkJggg==" alt="" />
除了userMapper.xml和Mybatis_mappertest.java要修改外,其他的代码都不用变。
userMapper.xml代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- nanmespace:命名空间。 作用就是对sql进行分类话管理,理解Sal分离 注意:使用mapper代理方式,namespace有特殊重要的作用
--> <mapper namespace="cn.itcast.mybatis.mapper.userMapper"> <!--
这里的id要和Mapp接口里面的函数名字一模一样。parameterType表示输入的类型,
resultType表示输出的类型 -->
<select id="findUserList" parameterType="cn.itcast.mybatis.po.UserQueryVo" resultType="cn.itcast.mybatis.po.UserCustom">
SELECT id ,username FROM USER WHERE user.sex= #{userCustom.sex} AND user.username=#{userCustom.username}
</select> <!--
定义resultMap
将SELECT id id_,username username_ FROM USER 和User类中的属性做一个映射关系 type:resultMap最终映射的java对象类型,可以使用别名
id:对resultMap的唯一标识。
-->
<resultMap type="user" id="userResultMap">
<!--
id:表示查询结果集中唯一的标识。
column:查询出来的列名
property:type指定的pojo类型中的属性名
最终resultMap对column和property作一个映射关系(对应关系) -->
<id column="id_" property="id"/>
<result column="username_" property="username"/>
</resultMap> <select id="findUserByResultMap" parameterType="cn.itcast.mybatis.po.UserQueryVo" resultMap="userResultMap">
SELECT id id_,username username_ FROM USER
<!-- where可以自动去掉条件中的第一个and
-->
<where>
<if test="userCustom!=null">
<if test="userCustom.sex!=null and userCustom.sex!=''">
and user.sex= #{userCustom.sex}
</if>
<if test="userCustom.username!=null and userCustom.username!=''" > and user.username=#{userCustom.username}
</if> </if> </where> </select> </mapper>
测试代码Mybatis_mappertest.java代码如下:
package cn.itcast.mybatis.first; import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List; import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test; import cn.itcast.mybatis.mapper.userMapper;
import cn.itcast.mybatis.po.User;
import cn.itcast.mybatis.po.UserCustom;
import cn.itcast.mybatis.po.UserQueryVo; public class Mybatis_mappertest { private SqlSessionFactory sqlSessionFactory;
@Before
public void setup() throws IOException
{ String resource="SqlMapConfig.xml";
InputStream inputStream= Resources.getResourceAsStream(resource);
//主要是生成SqlsessionFactory。
this.sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
}
@Test
public void testMaper()
{
SqlSession sqlSession=null; sqlSession=sqlSessionFactory.openSession();
//生成代理类
userMapper userMapper=sqlSession.getMapper(userMapper.class);
//创建包装对象,设置查询条件
UserQueryVo userQueryVo=new UserQueryVo();
UserCustom userCustom=new UserCustom(); // 注意我把这里的sex注销掉了,也就是说sex没有值,那么我们用的是动态的sql语句,就是说sex不会被拼接进去吧
// userCustom.setSex("1");
userCustom.setUsername("王王");
userQueryVo.setUserCustom(userCustom); userMapper.findUserByResultMap(userQueryVo); } }
运行如下:
DEBUG [main] - ==> Preparing: SELECT id id_,username username_ FROM USER WHERE user.username=?
看到没,这里得sql语句中没有 and user.sex= #{userCustom.sex}这条语句。也就是说没有拼接上去。
我们再改一下:干脆把整个userCustom都不输入进去。
结果如下:
DEBUG [main] - ==> Preparing: SELECT id id_,username username_ FROM USER
看到没,这里的sql语句中什么where后面的语句都没有拼接上去了。
16Mybatis_动态sql_if判断的更多相关文章
- MyBatis3_[tp_38~]_动态sql_if_判断&OGNL_where标签_
笔记要点出错分析与总结 /** 笔记: * 查询的时候,如果某些条件,没带可能SQL拼装会有问题; * 1.-->给where 后面加上 1=1, 以后的条件都and XXX * 2. < ...
- mybatis_05动态SQL_if和where
If标签:作为判断入参来使用的,如果符合条件,则把if标签体内的SQL拼接上. 注意:用if进行判断是否为空时,不仅要判断null,也要判断空字符串‘’: Where标签:会去掉条件中的第一个and符 ...
- java数组反射实现动态的判断一个对象是否是数组并且对数组进行拆包输出
public static Map<String, String> maptoMapString(Map<String, ?> map) { return map.entryS ...
- npoi的用法,动态的判断单元格的大小,设置列的宽度
public MemoryStream GridToExcelByNPOI(DataTable dt, string strExcelFileName) { HSSFWorkbook wk = new ...
- Vue 标签Style 动态三元判断绑定
<div :style=" 1==1 ? 'display:block' : 'display:none' "></div> v-bind:style 的 ...
- 动态sql语句,非存储过程,如何判断某条数据是否存在,如果不存在就添加一条
已知一个表 table 里面有两个字段 A1 和 A2 如何用动态语句 判断 A1 = A , A2=B 的数据是否存在,如果不存在,就添加一条数据, A1 = A , A2 = B INSERT ...
- c++ 动态判断基类指针指向的子类类型(typeid)
我们在程序中定义了一个基类,该基类有n个子类,为了方便,我们经常定义一个基类的指针数组,数组中的每一项指向都指向一个子类,那么在程序中我们如何判断这些基类指针是指向哪个子类呢? 本文提供了两种方法 ( ...
- mybatis入门基础(五)----动态SQL
一:动态SQL 1.1.定义 mybatis核心对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接.组装. 1.2.案例需求 用户信息综合查询列表这个statement的定义使用动态s ...
- Mybatis学习记录(五)----Mybatis的动态SQL
1. 什么是动态sql mybatis核心 对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接.组装. 1.1 需求 用户信息综合查询列表和用户信息查询列表总数这两个statemen ...
随机推荐
- SharePoint 2013 中自定义WCF服务
在使用SharePoint2013的时候,如果其他客户端 API 的组合不足,可以通过自定义 Web 服务扩展 SharePoint.默认情况下,SharePoint 2013 不仅支持创建自定义 A ...
- How to Use Telnet to Test SMTP Communication
Topic Last Modified: 2005-05-24 Telnet is an extremely useful tool for troubleshooting issues relate ...
- 通过sftp实现文件分发功能
1 环境: 分发服务器:ubuntu server 64bit,192.168.56.22 接受服务器:windows server 2008,192.168.56.102 2 ...
- JAVA基础学习day18--常用工具类
一.System 1.1.概述 System 类包含一些有用的类字段和方法.它不能被实例化. 在 System 类提供的设施中,有标准输入.标准输出和错误输出流:对外部定义的属性和环境变量的访问:加载 ...
- Silverlight项目笔记7:xml/json数据解析、TreeView、引用类型与数据绑定错误、图片加载、虚拟目录设置、silverlight安全机制引发的问题、WebClient缓存问题
1.xml/json数据解析 (1)xml数据解析 使用WebClient获取数据,获取到的数据实例化为一个XDocument,使用XDocument的Descendants(XName)方法获得对应 ...
- android学习笔记 对话框合集
package com.zhangbz.dialog; import android.app.Activity; import android.app.AlertDialog; import andr ...
- iOS开发之网络数据解析(一)--JSON解析简介
前言:对服务器请求之后,返回给客户端的数据,一般都是JSON格式或者XML格式(文件下载除外) 本篇随便先讲解JSON解析. 正文: 关于JSON: JSON是一种轻量级的数据格式,一般用于数据交互 ...
- DP大作战——多重背包
题目描述 在之前的上机中,零崎已经出过了01背包和完全背包,也介绍了使用-1初始化容量限定背包必须装满这种小技巧,接下来的背包问题相对有些难度,可以说是01背包和完全背包的进阶问题. 多重背包:物品可 ...
- Python UnicodeDecodeError
出于对goagent的兴趣,看了python,后来又想了解一下gae,于是就按照gae python创建hello world应用程序,可是一开始就遇到这样一个问题: UnicodeDecodeErr ...
- 【AdaBoost算法】基于OpenCV实现人脸检测Demo
一.关于检测算法 分类器训练: 通过正样本与负样本训练可得到分类器,opencv有编译好的训练Demo,按要求训练即可生成,这里我们直接使用其已经训练好的分类器检测: 检测过程: 检测过程很简单,可以 ...