<?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="com.data.dao.ExampleDao">
<resultMap id="exampleMap" type="Example">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="sex" column="sex" />
<result property="age" column="age" />
<result property="city" column="city" />
<result property="birthday" column="birthday" />
</resultMap>
<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>
</mapper>
mybatis配置
最新推荐文章于 2024-07-24 17:27:32 发布