<?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="${packageName}.mapper.${ClassName}Mapper">
    
    <resultMap type="${ClassName}" id="${ClassName}Result">
#foreach ($column in $columns)
        <result property="${column.javaField}"    column="${column.columnName}"    />
#end
    </resultMap>
#if($table.sub)

    <resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result">
        <collection property="${subclassName}List" ofType="${subClassName}" column="${pkColumn.columnName}" select="select${subClassName}List" />
    </resultMap>

    <resultMap type="${subClassName}" id="${subClassName}Result">
#foreach ($column in $subTable.columns)
        <result property="${column.javaField}"    column="${column.columnName}"    />
#end
    </resultMap>
#end

    <sql id="select${ClassName}Vo">
        select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName}
    </sql>

    <select id="queryListPage" parameterType="${ClassName}" resultMap="${ClassName}Result">
        <include refid="select${ClassName}Vo"/>
        <where>
            #foreach($column in $columns)
                #set($queryType=$column.queryType)
                #set($javaField=$column.javaField)
                #set($javaType=$column.javaType)
                #set($columnName=$column.columnName)
                #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
                #if($column.query)
                    #if($column.queryType == "EQ")
                        <if test="entity.$javaField != null #if($javaType == 'String' ) and entity.$javaField.trim() != ''#end"> and $columnName = #{entity.$javaField}</if>
                    #elseif($queryType == "NE")
                        <if test="entity.$javaField != null #if($javaType == 'String' ) and entity.$javaField.trim() != ''#end"> and $columnName != #{entity.$javaField}</if>
                    #elseif($queryType == "GT")
                        <if test="entity.$javaField != null #if($javaType == 'String' ) and entity.$javaField.trim() != ''#end"> and $columnName &gt; #{entity.$javaField}</if>
                    #elseif($queryType == "GTE")
                        <if test="entity.$javaField != null #if($javaType == 'String' ) and entity.$javaField.trim() != ''#end"> and $columnName &gt;= #{entity.$javaField}</if>
                    #elseif($queryType == "LT")
                        <if test="entity.$javaField != null #if($javaType == 'String' ) and entity.$javaField.trim() != ''#end"> and $columnName &lt; #{entity.$javaField}</if>
                    #elseif($queryType == "LTE")
                        <if test="entity.$javaField != null #if($javaType == 'String' ) and entity.$javaField.trim() != ''#end"> and $columnName &lt;= #{entity.$javaField}</if>
                    #elseif($queryType == "LIKE")
                        <if test="entity.$javaField != null #if($javaType == 'String' ) and entity.$javaField.trim() != ''#end"> and $columnName like concat('%', #{entity.$javaField}, '%')</if>
                    #elseif($queryType == "BETWEEN")
                        <if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if>
                    #end
                #end
            #end
        </where>
    </select>
</mapper>