<?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="${package}.modules.${module}.dao.${className}Mapper">
	
	<select id="listForPage" resultType="${package}.modules.${module}.entity.${className}Entity">
		SELECT
<% for(column in columns!) { %>
			`${column.columnName}`<% if(!columnLP.last) { %>, <% } %>
<% } %>
		FROM
			${tableName}
		ORDER BY
			${pk.columnName} DESC
	</select>
	
	<insert id="save">
		INSERT INTO ${tableName} (
<% for(column in columns!) { %>
<% if(column.columnName != pk.columnName || pk.extra != 'auto_increment') { %>
			`${column.columnName}`<% if(!columnLP.last) { %>, <% } %>
<% } %>
<% } %>
		)
		VALUES (
<% for(column in columns!) { %>
<% if(column.columnName != pk.columnName || pk.extra != 'auto_increment') { %>
			#{${column.fieldName}}<% if(!columnLP.last) { %>, <% } %>
<% } %>
<% } %>
		)
	</insert>
	
	<select id="getObjectById" resultType="${package}.modules.${module}.entity.${className}Entity">
		SELECT
<% for(column in columns!) { %>
			`${column.columnName}`<% if(!columnLP.last) { %>, <% } %>
<% } %>
		FROM
			${tableName}
		WHERE
			${pk.columnName} = #{${pk.fieldName}}
	</select>
	
	<update id="update">
		UPDATE ${tableName}
	 	<set>
<% for(column in columns!) { %>
<% if(column.columnName != pk.columnName) { %>
			<if test="${column.fieldName} != null">`${column.columnName}` = #{${column.fieldName}}<% if(!columnLP.last) { %>, <% } %></if>
<% } %>
<% } %>
		</set>
		WHERE
			${pk.columnName} = #{${pk.fieldName}}
	</update>
	
	<delete id="batchRemove">
		DELETE
		FROM
			${tableName}
		WHERE
			${pk.columnName} IN
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>