<?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.pj.project.tb_bank.TbBankMapper">

	<!-- 增 [G] -->
	<insert id="add">
		insert into 
		tb_bank (id, bank_name, bank_code) 
		values (#{id}, #{bankName}, #{bankCode}) 
	</insert>

	<!-- 删 -->
	<delete id="delete">
		delete from tb_bank 
		where id = #{id}
	</delete>

	<!-- 改 [G] -->
	<update id="update">
		update tb_bank set
		id = #{id}, 
		bank_name = #{bankName}, 
		bank_code = #{bankCode}
		where id = #{id}
	</update>


	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, bank_name, bank_code from tb_bank  -->
	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.tb_bank.TbBank">
		<result property="id" column="id" />
		<result property="bankName" column="bank_name" />
		<result property="bankCode" column="bank_code" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select * 
		from tb_bank 
	</sql>
	
	<!-- 查 - 根据id -->
	<select id="getById" resultMap="model">
		<include refid="select_sql"></include>
		where id = #{id}
	</select>
	
	<!-- 查集合 - 根据条件（参数为空时代表忽略指定条件） [G] -->
	<select id="getList" resultMap="model">
		<include refid="select_sql"></include>
		<where>
			<if test=' this.isNotNull("id") '> and id = #{id} </if>
			<if test=' this.isNotNull("bankName") '> and bank_name = #{bankName} </if>
			<if test=' this.isNotNull("bankCode") '> and bank_code = #{bankCode} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 2'> bank_name desc </when>
			<when test='sortType == 3'> bank_code desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
