<sql id="findExampleBaseSql">
SELECT id, name, sex, age, city, birthday
</sql>
<!-- 分页查询条件sql -->
<sql id="searchExampleBaseSql">
<where>
1 = 1
<if test="condition.name != null">
AND name LIKE CONCAT('%','${condition.name}','%' )
</if>
<if test="condition.city != null">
AND city LIKE CONCAT('%','${condition.city}','%' )
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="listExample" resultMap="exampleMap" parameterType="java.util.Map">
<include refid="findExampleBaseSql" />
FROM example
<include refid="searchExampleBaseSql" />
<if test="sort != null">
ORDER BY #{sort} DESC
</if>
LIMIT #{first}, #{size}
</select>
<!-- 分页查询统计 -->
<select id="countExample" resultType="java.lang.Integer">
SELECT COUNT(*) FROM example
<include refid="searchExampleBaseSql" />
</select>
<!-- insertExample -->
<insert id="insertExample" parameterType="Example" useGeneratedKeys="true" keyProperty="id">
<![CDATA[
INSERT INTO example
(name, sex, age, city, birthday)
VALUES
(#{name}, #{sex}, #{age}, #{city}, #{birthday} )
]]>
</insert>
<!-- getExampleById -->
<select id="getExampleById" parameterType="java.lang.Long" resultMap="exampleMap">
<include refid="findExampleBaseSql" />
<![CDATA[
FROM example WHERE id = #{id}
]]>
</select>
<update id="updateExample" parameterType="Example">
<![CDATA[
UPDATE
example
SET
name = #{name},
sex = #{sex},
age = #{age},
city = #{city},
birthday = #{birthday}
WHERE
id = #{id};
]]>
</update>