mybatis配置

<?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> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值