<?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="${bean.pacageName}${bean.modulesName}.dao.${bean.className}Dao">
	<!-- Result Map -->
	<resultMap id="BaseResultMap" type="${bean.pacageName}${bean.modulesName}.bean.${bean.className}">
	    <#list bean.fields as field>
	    <result column="${field.fieldName}" property="${field.fieldJavaName}"/>
		</#list>
	</resultMap>

	<!-- ${bean.tableName} table all fields -->
	<sql id="Base_Column_List">
		<#list bean.fields as field><#if field_index==0>${field.fieldName}</#if><#if field_index!=0>,${field.fieldName}</#if></#list>
	</sql>

	<!-- 公共查询条件 -->
	<sql id="Example_Where_Clause">
		where t.deleted=0
		<#list bean.fields as field>
		<if test="${field.fieldJavaName}!=null <#if field.fieldType=="varchar">and ${field.fieldJavaName}!=''</#if>">and t.${field.fieldName} = _#_{${field.fieldJavaName}}</if>
		</#list>
	</sql>

	<select id="queryPageByCount" parameterType="Object" resultType="java.lang.Integer">
	select count(1) from ${bean.tableName} t
	<include refid="Example_Where_Clause"/>
	</select>

	<select id="queryPageList" parameterType="Object" resultMap="BaseResultMap">
	select t.* from ${bean.tableName} t
	<include refid="Example_Where_Clause"/>
	<if test="pager.orderCondition != null and pager.orderCondition != ''">
		_$_{pager.orderCondition}
	</if>
	<if test="pager.mysqlQueryCondition != null and pager.mysqlQueryCondition != ''">
		_$_{pager.mysqlQueryCondition}
	</if>
	</select>

</mapper>


