1.trim prefix prefixOverrides suffix suffixOverrides
---通常用法---
例子1-1(以字符“where”覆盖首个“and”或"or”字符):
<!--prefix & prefixOverrides--> <select id="findUserById" resultType="user"> select * from user <trim prefix="where" prefixOverrides="and|or "> <if test="id != null"> id=#{id} </if> and deleteFlag=0; </trim> </select>
等效于
<select id="findUserById" resultType="user"> select * from user <where> <if test="id != null"> id=#{id} </if> and deleteFlag=0; </where> </select>
当id为空,生成的sql语句为:
//deleteFlag前的"and"被去掉 select * from user where deleteFlag=0;
例子1-2(为trim括起来的语句添加"set"字符前缀,并且覆盖去掉最后面的","字符):
<!--主要看suffixOverrides的用法--> <update id="updateUser" parameterType="com.dy.entity.User"> update user <trim prefix="set" suffixOverrides=","> <if test="name != null">name = #{name},</if> <if test="password != null">password = #{password},</if> </trim> <where> <if test="id != null"> id = #{id} </if> and deleteFlag = 0; </where> </update>
等效于
<update id="updateUser" parameterType="com.dy.entity.User"> update user <set> <if test="name != null">name = #{name},</if> <if test="password != null">password = #{password},</if> </set> <where> <if test="id != null"> id = #{id} </if> and deleteFlag = 0; </where> </update>
生成的sql语句为:
//password后的","被去掉 update user set name = #{name},password = #{password} where id = #{id} and deleteFlag = 0;
注:prefix prefixOverrides suffix suffixOverrides并非需要配套使用,可以任意组合或者单个使用,具体情况按实际需求
2.foreach
<select id="selectPostIn" resultType="domain.blog.Post"> SELECT * FROM POST P WHERE ID in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach> </select>
相关推荐
本工程为 MyBatis-Plus 的官方示例,项目结构如下: mybatis-plus-sample-quickstart: 快速开始示例 mybatis-plus-sample-quickstart-springmvc: 快速开始示例(Spring MVC版本) mybatis-plus-sample-reduce-...
mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip ...
mybatis在持久层框架中还是比较火的,一般项目都是基于ssm。虽然mybatis可以直接在xml中...《MyBatis-Plus入门文档》主要介绍了MyBatis-Plus入门使用,以及关于mybatis-plus的更多介绍及特性,感兴趣的可以下载学习一下
赠送jar包:mybatis-plus-boot-starter-3.5.1.jar; 赠送原API文档:mybatis-plus-boot-starter-3.5.1-javadoc.jar; 赠送源代码:mybatis-plus-boot-starter-3.5.1-sources.jar; 赠送Maven依赖信息文件:mybatis-...
赠送jar包:mybatis-plus-extension-3.5.1.jar; 赠送原API文档:mybatis-plus-extension-3.5.1-javadoc.jar; 赠送源代码:mybatis-plus-extension-3.5.1-sources.jar; 赠送Maven依赖信息文件:mybatis-plus-...
赠送jar包:mybatis-spring-2.0.0.jar; 赠送原API文档:mybatis-spring-2.0.0-javadoc.jar; 赠送源代码:mybatis-spring-2.0.0-sources.jar; 赠送Maven依赖信息文件:mybatis-spring-2.0.0.pom; 包含翻译后的API...
赠送jar包:mybatis-plus-annotation-3.5.1.jar; 赠送原API文档:mybatis-plus-annotation-3.5.1-javadoc.jar; 赠送源代码:mybatis-plus-annotation-3.5.1-sources.jar; 赠送Maven依赖信息文件:mybatis-plus-...
mybatis配置的重要文件包括mybatis-3-config.dtd mybatis-3-mapper.dtd
mybatis-plus源码(mybatis-plus-3.5.1.zip)
赠送jar包:mybatis-spring-boot-autoconfigure-1.3.2.jar; 赠送原API文档:mybatis-spring-boot-autoconfigure-1.3.2-javadoc.jar; 赠送源代码:mybatis-spring-boot-autoconfigure-1.3.2-sources.jar; 赠送...
mybatis源码是mybatis-3.2.6的源码,用户使用mybatis时可以进行参考
mybatis-generator-config_1_0.dtd文件存在于mybatis-generator-core-1.3.2.jar包中,路径如下org/mybatis/generator/config/xml/mybatis-generator-config_1_0.dtd 可以设置开发工具的dtd配置,配置...
开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2...
mybatis-3.2.8 Releases版 与 mybatis-3.3.0 SNAPSHOT版本
赠送jar包:mybatis-generator-core-1.3.7.jar; 赠送原API文档:mybatis-generator-core-1.3.7-javadoc.jar; 赠送源代码:mybatis-generator-core-1.3.7-sources.jar; 赠送Maven依赖信息文件:mybatis-generator-...