Mybatis-sql语句的抽取
1.抽取之前的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">
<mapper namespace="com.hao.mapper.UserMapper">
<select id="findByCondition" parameterType="user" resultType="user">
select * from user
<where>
<if test="id!=0">
and id=#{id}
</if>
<if test="username!=null">
and username=#{username}
</if>
<if test="password!=null">
and password=#{password}
</if>
</where>
</select>
<select id="findByIds" parameterType="list" resultType="user">
select * from user
<where>
<foreach collection="list" open="id in(" close=")" item="id" separator=",">
#{id}
</foreach>
</where>
</select>
</mapper>
2.抽取之后的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">
<mapper namespace="com.hao.mapper.UserMapper">
<!-- sql语句的抽取-->
<sql id="selectUser">select * from user</sql>
<select id="findByCondition" parameterType="user" resultType="user">
<include refid="selectUser"></include>
<where>
<if test="id!=0">
and id=#{id}
</if>
<if test="username!=null">
and username=#{username}
</if>
<if test="password!=null">
and password=#{password}
</if>
</where>
</select>
<select id="findByIds" parameterType="list" resultType="user">
<include refid="selectUser"></include>
<where>
<foreach collection="list" open="id in(" close=")" item="id" separator=",">
#{id}
</foreach>
</where>
</select>
</mapper>
refid:引用
Mybatis-sql语句的抽取的更多相关文章
- ibatis mybatis sql语句配置 符号不兼容 大于号 小于号<!CDATA[ ]>
ibatis mybatis sql语句配置 符号不兼容 大于号 小于号<!CDATA[ ]> 因为这个是xml格式的,所以不允许出现类似">"这样的字符,但是都 ...
- mybatis sql语句中 in() 长度为0或null的情况
mybatis sql语句中 in() 长度为0或null的情况 比如: select * from A where colName IN <foreach collection="m ...
- Mybatis SQL语句查询
MyBatis中使用in查询时的注意事项 foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach一共有三种类型,分别为List,[](array),Map三种. ...
- MyBatis SQL语句操作Mysql
本文记录使用Mybatis操作数据库时碰到的一些语句,供以后参考. 一,多条件查询 示意SQL语句:SELECT t_field1, t_field2 FROM table_name WHERE t_ ...
- Mybatis——SQL语句构建器类
SQL语句构建器类 问题 Java程序员面对的最痛苦的事情之一就是在Java代码中嵌入SQL语句.这么来做通常是由于SQL语句需要动态来生成-否则可以将它们放到外部文件或者存储过程中.正如你已经看到的 ...
- MyBatis Sql语句中的转义字符
1.在xml的sql语句中,不能直接用大于号.小于号要用转义字符 如果用小于号会报错误如下: org.apache.ibatis.builder.BuilderException: Error cre ...
- mybatis sql语句符号问题
写sql语句<或>不能直接写,而应写作<或>,不然项目不能正常编译启动
- 160311、mybatis sql语句中转义字符
问题: 在mapper ***.xml中的sql语句中,不能直接用大于号.小于号要用转义字符 解决方法: 1.转义字符串 小于号 < < 大于号 > & ...
- mybatis sql语句#{}和${}区别联系
1.说白了就是,#{}用于引用字符变量,如varchar,string.因为sql语句执行过程中要给string varchar加‘’来执行. 2.${}用来引用int型等不需要添加单引号的值 3.具 ...
- mybatis sql语句中转义字符
问题: 在mapper ***.xml中的sql语句中,不能直接用大于号.小于号要用转义字符 解决方法: 1.转义字符串 小于号 < < 大于号 > & ...
随机推荐
- Centos7 环境下设置固定IP
1. 在/etc/sysconfig/network-scripts/下创建ifcfg-eth0配置文件, 并填入以下内容: DEVICE=eth0 TYPE=Ethernet IPADDR=192. ...
- mac电脑sublime text3安装pretty json插件
因http://packagecontrol.io/地址被墙无法实现自动安装,导致sublime Text3安装插件非常麻烦,总是出现There Are No Packages Available F ...
- 关于alertmanager报No private IP address found, and explicit IP not provided
./alertmanager --config.file=alertmanager.yml level=info ts=2021-11-22T05:53:11.195Z caller=main.go: ...
- prometheus虚拟化安装脚本
在线安装下载链接:https://files.cnblogs.com/files/blogs/705493/online_prometheus.sh 离线安装下载链接:https://files.cn ...
- 从零开始,开发一个 Web Office 套件(12):删除文字 & 回车换行
这是一个系列博客,最终目的是要做一个基于 HTML Canvas 的.类似于微软 Office 的 Web Office 套件(包括:文档.表格.幻灯片--等等). 博客园:<从零开始, 开发一 ...
- python+pytest接口自动化(11)-测试函数、测试类/测试方法的封装
前言 在python+pytest 接口自动化系列中,我们之前的文章基本都没有将代码进行封装,但实际编写自动化测试脚本中,我们都需要将测试代码进行封装,才能被测试框架识别执行. 例如单个接口的请求代码 ...
- 西门子S210驱动器接线
参考:SINAMICS S210 操作说明 1.系统概述 P28 节2.2 单相版驱动器的系统组件和附件 2.电源接线 P56 节3.2 单相 230 V 版驱动器的连接示例 单相版驱动器在 IT 电 ...
- STM32芯片去除读写保护 | 使用ST-Link Utility去除STM32芯片读写保护
1.使用ST-LINK V2下载器连接到STM32芯片, 点击Connect: 2.存在读保护: 3.修改选项字节(Option Bytes... ): 4.将读保护修改为Disabled. 5.打钩 ...
- JDK API文档_1.6.0 中文版
链接:https://pan.baidu.com/s/1b0inUgYvEfjeusa3z_2p-g 密码:f8jk
- redux和vuex以及dva?
redux: 通过store存储,通过action唯一更改,reducer描述如何更改.dispatch一个action dva: 基于redux,结合redux-saga等中间件进行封装 vuex: ...