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语句的抽取相关推荐

  1. MyBatis SQL语句详解

    MyBatis SQL语句详解 1 CRUD标签 1.1 select 1.2 insert 1.3 update 1.4 delete 1.5 #{ }和${ }的区别 2 动态SQL 2.1 if ...

  2. MyBatis SQL语句操作Mysql

    本文记录使用Mybatis操作数据库时碰到的一些语句,供以后参考. 一,多条件查询 示意SQL语句:SELECT t_field1, t_field2 FROM table_name WHERE t_ ...

  3. log4j打印mybatis sql语句

    2019独角兽企业重金招聘Python工程师标准>>> Mybatis默认使用有slf4j 必须加上依赖 <dependency> <groupId>org. ...

  4. [mybatis] sql语句无错误,但是执行多条sql语句时,抛出java.sql.SQLSyntaxErrorException...

    错误内容 org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: java.sql.S ...

  5. [mybatis] sql语句无错误,但是执行多条sql语句时,抛出java.sql.SQLSyntaxErrorException

    错误内容 org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: java.sql.S ...

  6. slf4j + logback 输出日志:mybatis sql语句

    1 引入jar包:maven resposity 中 选择logback classic module <dependency> <groupId>ch.qos.logback ...

  7. 在maven web项目中配置log4j打印日志及Mybatis sql语句

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wei542657623/article/details/51591736 1 添加依赖 在pom.x ...

  8. Mybatis SQL 语句中 IF函数不支持

    只能将 IF 替换成 CASE WHEN A THEN AA ELSE BB END 转载于:https://www.cnblogs.com/mengjianzhou/p/11506344.html

  9. mybatis入门(六)之SQL语句构建器类

    转载自    mybatis SQL语句构建器类 问题 Java程序员面对的最痛苦的事情之一就是在Java代码中嵌入SQL语句.这么来做通常是由于SQL语句需要动态来生成-否则可以将它们放到外部文件或 ...

  10. statement执行insert into语句_【图文并茂】源码解析MyBatis ShardingJdbc SQL语句执行流程详解...

    源码分析Mybatis系列目录: 1.源码分析Mybatis MapperProxy初始化[图文并茂] 2.源码分析Mybatis MappedStatement的创建流程 3.[图文并茂]Mybat ...

最新文章

  1. 设计中的版面艺术!你造吗?(四)
  2. linux登录ssh怎么保存采集的脚本,ssh自动登录并且su的脚本
  3. java js关键字_JavaScript关键字和保留字
  4. 【CodeForces - 689B】Mike and Shortcuts(Dijkstra最短路,或者bfs跑状态类似spfa)
  5. 小甲鱼 OllyDbg 教程系列 (十六) : 简单病毒的逆向分析
  6. 计算机考试模拟系统无法进入,全国计算机等级考试上机考试模拟系统使用说明...
  7. Bailian2750 鸡兔同笼【入门】
  8. 深入理解JavaScript系列
  9. WeaveScope-容器监控
  10. Windows DOS命令总结大全
  11. 推荐几本计算流体力学(CFD)书籍
  12. 第二章 Python数据类型和运算符
  13. 计算机连接网络被限制,本地连接受限制或无连接怎么办很简单解决教程
  14. (附源码)小程序 酒店疫情系统 毕业设计 091931
  15. 标签类目体系(面向业务的数据资产设计方法论)-读书笔记8(完结)
  16. php substr 中文_PHP mb_substr():截取中文字符串
  17. 2022年大中华区最佳职场榜单公布,共有92家企业入选 | 美通社头条
  18. 2020-05-06
  19. 使用gitbash创建一个翻译词典
  20. 水货iPad 2价格骤降数千元

热门文章

  1. nuget pack
  2. ASP.NET MVC 2 验证
  3. 我收集的学习网址,O(∩_∩)O~
  4. 电话开启和电话关闭的命令
  5. laravel 调试mysql_Laravel - MySQL数据库的使用详解3(Query Builder用法2:新增、修改、删除)...
  6. linux系统的数据库是本地吗,Linux下MySQL无法在本地以非root用户身份连接数据库...
  7. rgb sw 线主板接口在哪_十代至尊i910980XE直接上:技嘉X299X AORUS MASTER主板评测
  8. php sprintf 后面补0,PHP数字前补0的自带函数sprintf 和number_format的用法(详解)
  9. 1.搭建Spring环境
  10. 主存块和cache块关系_Cache(直接相联)