Mybatis-sql语句的抽取
2024-09-08 02:11:01
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:引用
最新文章
- list<;T>; 的使用方法。
- 关于C#消息调度(作业日志)
- MAVEN解决Cannot change version of project facet Dynamic web module to 2.5
- (HBase) Error: JAVA_HOME is not set and Java could not be found
- 引擎设计跟踪(九.14.2c) 最近一些小的更新
- 【转】google谷歌百度收录网站的技巧方法,如何让百度收录?
- ping 命令详解
- 点点滴滴-ConfigurationManager.AppSettings
- IIS由于无法创建应用程序域,因此未能执行请求。错误: 0x80070005 拒绝访问
- TeamCity vs Jenkins: Which is the Better Continuous Integration (CI) Server for .NET Software Development?
- SQL server学习(一)数据库的基本知识、基本操作(分离、脱机、收缩、备份、还原、附加)和基本语法
- 【BZOJ1001】狼抓兔子(网络流)
- RESTful levels 和 HATEOAS
- 取消IE、Office、Wmp首次开启提示
- yii2开启事务
- SQL语句内做除法得出百分比
- 清华镜像站安装docker
- jqzoom插件图片放大功能的一些BUG
- POJ2396:Budget(带下界的网络流)
- npm模块安装机制
热门文章
- LGP5992题解
- Java &;、&;&;、|、||、^、<;<;、>;>;、~、>;>;>;等运算符
- python+pytest接口自动化(9)-cookie绕过登录(保持登录状态)
- Spring 中的 bean线程安全性分析
- logging 日志模块 configparser 配置文件
- 到底为什么不建议使用SELECT *?
- leetcode-3无重复字符的最长子串
- 什么情况下一个 broker 会从 isr中踢出去?
- Docker配置PostgreSQL数据本地持久化
- Javascript Range对象的学习