mybatis mapper配置文件 CustomerMapper.xml

Dao

@Repository
public interface CustomerDAO {
    public void create(CustomerModel cm);
    public void update(CustomerModel cm);
    public void delete(CustomerModel cm);
    
    public CustomerModel getByUuid(int uuid);
    
    public List<CustomerModel> getByCondition(CustomerQueryModel cqm);
            
}

实体

public class CustomerModel {
    private Integer uuid;
    private String customerId;
    private String pwd;
    private String showName;
    private String trueName;
    private String registerTime;

}

<?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.exayong.architecture1.customermgr.dao.CustomerDAO">
    <insert id="create" parameterType="CM">
        insert into
        tbl_customer(customerId,pwd,showName,trueName,registerTime)values(#{customerId},#{pwd},#{showName},#{trueName},#{registerTime})
    </insert>
    <update id="update" parameterType="CM">
        update tbl_customer set
        customerId=#{customerId},pwd=#{pwd},showName=#{showName},trueName=#{trueName},registerTime=#{registerTime}
        where uuid=#{uuid}
    </update>

    <delete id="delete" parameterType="Int">
        delete from tbl customer where uuid=#{uuid}

    </delete>

    <select id="getByUuid" parameterType="Int" resultType="CM">
        select * from tbl_customer where uuid=#{_uuid}

    </select>
    <select id="getByCondition" parameterType="CQM" resultType="CM">
        select * from tbl_customer
        <where>
            <if test="uuid=null &amp;&amp; uuid >0">
                and uuid=#{_uuid}

            </if>
            <if test="customerId=null">
                and customerId=#{customerId}

            </if>
            <if test="showName=null">
                and showName=#{showName}
            </if>
        </where>

    </select>
</mapper>

原文地址:https://www.cnblogs.com/exayong/p/6507370.html