<?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">
<!--  Copyright (c) ${Company} Corporation ${Year} . All rights reserved. -->
<!--  Mybatis数据库持久层（业务层映射文件）：${javaClassRef.getComment()} -->
<!--  version: ${Version}  -->
<!--  author:  ${Author}    -->
<!--  date:  ${now}  -->
<mapper namespace="${daoPackage}.${javaClassRef.getClassName()}Dao">

#foreach( ${indexInfo} in ${tableRef.getIndexInfoRefs()})
  <select id="findBy${indexInfo.getCamelIndexName()}" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
#set($count=0)
#foreach( ${indexColumn} in ${indexInfo.getColumnRefList()})
      AND ${indexColumn.getName()} = #{${count}}
#set($count=$count+1)
#end
    </trim>
  </select>
#end

  <!-- 请在本文件内添加自定义SQL语句 -->

  <resultMap id="DetailMap" type="${dtoPackage}.${javaClassRef.getClassName()}DetailDto">
#foreach( ${column} in ${tableRef.getColumns()} )
  #if( ${column.isPrimaryKey()})
    <!-- ${column.getComment()} -->
    <id column="${column.getName()}" jdbcType="${column.getAttributesRef().getJdbcTypeName()}" property="${column.getAttributesRef().getRefName()}"/>
  #end
#end
#foreach( ${column} in ${tableRef.getColumns()} )
  #if( ${column.isPrimaryKey()})
  #else
    <!-- ${column.getComment()} -->
    <result column="${column.getName()}" jdbcType="${column.getAttributesRef().getJdbcTypeName()}" property="${column.getAttributesRef().getRefName()}"/>
  #end
#end
  </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="${entityPackage}.${javaClassRef.getClassName()}">
    select
#foreach( ${column} in ${tableRef.getColumns()} )
#if(${velocityCount} == 1)
    ${column.getName()}
#else
    ,${column.getName()}
#end
#end
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
#foreach( ${column} in ${tableRef.getColumns()} )
      <if test="${column.getAttributesRef().getRefName()} != null">
        AND ${column.getName()} = #{${column.getAttributesRef().getRefName()},jdbcType=${column.getAttributesRef().getJdbcTypeName()}}
      </if>
#end
    </trim>
  </select>
</mapper>