easymybatis.commonSql.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="common"> <!-- 自定义字段 --> <sql id="selfColumns"> <foreach collection="columns" item="column" separator="," > ${column} </foreach> </sql> <!-- 其它表字段 --> <sql id="otherTableColumns"> <if test="otherTableColumns!=null"> <trim prefix="," suffixOverrides=","> <foreach collection="otherTableColumns" item="column" separator="," > ${column} </foreach> </trim> </if> </sql> <sql id="sqlColumns"> <choose> <when test="columns.size>0"> <include refid="common.selfColumns" /> </when> <otherwise> <include refid="baseColumns" /> </otherwise> </choose> <include refid="common.otherTableColumns" /> </sql> <sql id="orderBy"> <if test="orderable"> ORDER BY ${order} </if> </sql> <sql id="limit"> <if test="!isQueryAll"> LIMIT #{start},#{limit} </if> </sql> <sql id="join"> <if test="joinExpressions!=null"> <foreach collection="joinExpressions" item="joinExpressionsItem"> ${joinExpressionsItem.joinSql} </foreach> </if> </sql> <sql id="condition"> <if test="valueExpressions!=null"> <foreach collection="valueExpressions" item="valueExpressionsItem"> <if test="valueExpressionsItem.value != null"> ${valueExpressionsItem.joint} ${valueExpressionsItem.column} ${valueExpressionsItem.equal} #{valueExpressionsItem.value} </if> </foreach> </if> <if test="listExpressions!=null"> <foreach collection="listExpressions" item="listExpressionsItem"> <if test="listExpressionsItem.value.size>0"> ${listExpressionsItem.joint} ${listExpressionsItem.column} ${listExpressionsItem.equal} <foreach collection="listExpressionsItem.value" item="value" open="(" separator="," close=")"> #{value} </foreach> </if> </foreach> </if> <if test="sqlExpressions!=null"> <foreach collection="sqlExpressions" item="sqlExpressionsItem"> ${sqlExpressionsItem.joint} (${sqlExpressionsItem.sql}) </foreach> </if> </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> <sql id="updateWhere"> <if test="query.joinExpressions!=null"> <foreach collection="query.joinExpressions" item="joinExpressionsItem"> ${joinExpressionsItem.joinSql} </foreach> </if> <where> <if test="query.valueExpressions!=null"> <foreach collection="query.valueExpressions" item="valueExpressionsItem"> <if test="valueExpressionsItem.value != null"> ${valueExpressionsItem.joint} ${valueExpressionsItem.column} ${valueExpressionsItem.equal} #{valueExpressionsItem.value} </if> </foreach> </if> <if test="query.listExpressions!=null"> <foreach collection="query.listExpressions" item="listExpressionsItem"> <if test="listExpressionsItem.value.size>0"> ${listExpressionsItem.joint} ${listExpressionsItem.column} ${listExpressionsItem.equal} <foreach collection="listExpressionsItem.value" item="value" open="(" separator="," close=")"> #{value} </foreach> </if> </foreach> </if> <if test="query.sqlExpressions!=null"> <foreach collection="query.sqlExpressions" item="sqlExpressionsItem"> ${sqlExpressionsItem.joint} (${sqlExpressionsItem.sql}) </foreach> </if> </where> </sql> <!-- 聚合查询 --> <!-- 查询列 --> <sql id="projectionColumn"> <foreach collection="projectionList.projections" item="projection" separator=","> ${projection.sql} </foreach> </sql> <!-- group by --> <sql id="groupBy"> <if test="groupByList.projections.size>0"> GROUP BY <foreach collection="groupByList.projections" item="projection" separator="," > ${projection.sql} </foreach> </if> </sql> <!-- having --> <sql id="having"> <trim prefix="HAVING" prefixOverrides="AND|OR"> <if test="valueHavingExpressions!=null"> <foreach collection="valueHavingExpressions" item="valueExpressionsItem"> <if test="valueExpressionsItem.value != null"> ${valueExpressionsItem.joint} ${valueExpressionsItem.column} ${valueExpressionsItem.equal} #{valueExpressionsItem.value} </if> </foreach> </if> <if test="listHavingExpressions!=null"> <foreach collection="listHavingExpressions" item="listExpressionsItem"> <if test="listExpressionsItem.value!=null"> ${listExpressionsItem.joint} ${listExpressionsItem.column} ${listExpressionsItem.equal} <foreach collection="listExpressionsItem.value" item="value" open="(" separator="," close=")"> #{value} </foreach> </if> </foreach> </if> <if test="sqlHavingExpressions!=null"> <foreach collection="sqlHavingExpressions" item="sqlExpressionsItem"> ${sqlExpressionsItem.joint} (${sqlExpressionsItem.sql}) </foreach> </if> </trim> </sql> </mapper>
© 2015 - 2024 Weber Informatics LLC | Privacy Policy