mybatis.mapping.base.Base.xml Maven / Gradle / Ivy
<?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="Base"> <!--或者--> <sql id="or"> ${key.condition} ${key.column} <choose> <when test="value.length == 1"> = <foreach collection="value" item="item"> #{item} </foreach> </when> <when test="value.length > 1"> in <foreach collection="value" item="item" open="(" close=")" separator=","> #{item} </foreach> </when> </choose> </sql> <sql id="query"> <where> <if test="q.params != null"> <foreach collection="q.params.entrySet()" item="value" index="key"> <choose> <when test="key.condition == 'in'.toString()"> and ${key.column} ${key.condition} <foreach collection="value" item="item" open="(" close=")" separator=","> #{item} </foreach> </when> <when test="key.condition == 'not in'.toString()"> and ${key.column} ${key.condition} <foreach collection="value" item="item" open="(" close=")" separator=","> #{item} </foreach> </when> <when test="key.condition == 'or'.toString() "> <include refid="Base.or" /> </when> <otherwise> and ${key.column} ${key.condition} #{value} </otherwise> </choose> </foreach> </if> </where> </sql> <sql id="sql"> <include refid="Base.query" /> <if test="q.groupBy != null"> ${q.groupBy.key} <foreach collection="q.groupBy.groupBy" item="item" separator=","> ${item} </foreach> </if> <if test="q.orderBy != null"> ${q.orderBy.key} <foreach collection="q.orderBy.orderBy" item="item" separator=","> ${item} </foreach> </if> <if test="q.page != null"> <choose> <when test="q.page.index != null"> limit #{q.page.index},#{q.page.pageSize} </when> <otherwise> limit #{q.page.pageSize} </otherwise> </choose> </if> </sql> <sql id="update"> <include refid="Base.updateSet" /> <include refid="Base.query" /> </sql> <sql id="add"> <foreach collection="q.fields" item="item" close=")" open="(" separator=","> ${item} </foreach> values <foreach collection="q.addValues" item="item" separator=","> <foreach collection="item.entrySet()" close=")" open="(" item="value" separator=","> #{value} </foreach> </foreach> </sql> <sql id="updateSet"> <foreach collection="q.updateMap.entrySet()" item="value" index="key" separator=","> <choose> <when test="key.isPoundSign"> ${key.fieldName} = #{value} </when> <otherwise> ${key.fieldName} = ${value} </otherwise> </choose> </foreach> </sql> </mapper>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy