fastmybatis.commonSql.xml Maven / Gradle / Ivy
The newest version!
<?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="common"> <sql id="orderBy"> <if test="query.orderable"> ORDER BY ${query.order} </if> </sql> <sql id="limit"> <if test="!query.isQueryAll"> LIMIT #{query.start},#{query.limit} </if> </sql> <sql id="join"> <if test="query.joinExpressions!=null"> <foreach collection="query.joinExpressions" item="joinExpressionsItem"> ${joinExpressionsItem.joinSql} </foreach> </if> </sql> <sql id="condition"> <foreach collection="query.expressions" item="expressionItem"> <if test='expressionItem.type == "VALUE"'> ${expressionItem.joint} ${expressionItem.column} ${expressionItem.equal} #{expressionItem.value} </if> <if test='expressionItem.type == "IN"'> ${expressionItem.joint} ${expressionItem.column} ${expressionItem.equal} <foreach collection="expressionItem.value" item="value" open="(" separator="," close=")"> #{value} </foreach> </if> <if test='expressionItem.type == "BETWEEN"'> ${expressionItem.joint} ${expressionItem.column} BETWEEN #{expressionItem.startValue} AND #{expressionItem.endValue} </if> <if test='expressionItem.type == "SQL"'> ${expressionItem.joint} (${expressionItem.sql}) </if> <if test='expressionItem.type == "SUB"'> ${expressionItem.joint} <if test="expressionItem.condition.expressions.size > 1"> ( </if> <foreach collection="expressionItem.condition.expressions" item="subExpressionItem" index="idx"> <if test='subExpressionItem.type == "VALUE"'> <if test="idx>0">${subExpressionItem.joint}</if> ${subExpressionItem.column} ${subExpressionItem.equal} #{subExpressionItem.value} </if> <if test='subExpressionItem.type == "IN"'> <if test="idx>0">${subExpressionItem.joint}</if> ${subExpressionItem.column} ${subExpressionItem.equal} <foreach collection="subExpressionItem.value" item="value" open="(" separator="," close=")"> #{value} </foreach> </if> <if test='subExpressionItem.type == "BETWEEN"'> <if test="idx>0">${subExpressionItem.joint}</if> ${subExpressionItem.column} BETWEEN #{subExpressionItem.startValue} AND #{subExpressionItem.endValue} </if> <if test='subExpressionItem.type == "SQL"'> <if test="idx>0">${subExpressionItem.joint}</if> (${subExpressionItem.sql}) </if> </foreach> <if test="expressionItem.condition.expressions.size > 1"> ) </if> </if> </foreach> </sql> <!-- 条件语句块 --> <sql id="where"> <include refid="common.join"/> <where> <include refid="common.condition"/> </where> </sql> <sql id="all"> <include refid="common.where"/> <include refid="common.orderBy"/> <include refid="common.limit"/> </sql> </mapper>