123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?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_item.TbItemMapper">
- <!-- 增 [G] -->
- <insert id="add">
- insert into
- tb_item (id, type_id, type_name, item_code, item_name, price, unit)
- values (#{id}, #{typeId}, #{typeName}, #{itemCode}, #{itemName}, #{price}, #{unit})
- </insert>
- <!-- 删 -->
- <delete id="delete">
- delete from tb_item
- where id = #{id}
- </delete>
- <!-- 改 [G] -->
- <update id="update">
- update tb_item set
- id = #{id},
- type_id = #{typeId},
- type_name = #{typeName},
- item_code = #{itemCode},
- item_name = #{itemName},
- price = #{price},
- unit = #{unit}
- where id = #{id}
- </update>
- <!-- ================================== 查询相关 ================================== -->
- <!-- select id, type_id, type_name, item_code, item_name, price, unit from tb_item -->
- <!-- 通用映射:手动模式 -->
- <resultMap id="model" type="com.pj.project.tb_item.TbItem">
- <result property="id" column="id" />
- <result property="typeId" column="type_id" />
- <result property="typeName" column="type_name" />
- <result property="itemCode" column="item_code" />
- <result property="itemName" column="item_name" />
- <result property="price" column="price" />
- <result property="unit" column="unit" />
- </resultMap>
- <!-- 公共查询sql片段 -->
- <sql id="select_sql">
- select *
- from tb_item
- </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.has("id") '> and id = #{id} </if>
- <if test=' this.has("itemCode") '> and item_code = #{itemCode} </if>
- <if test=' this.has("itemName") '> and item_name = #{itemName} </if>
- <if test=' this.has("price") '> and price = #{price} </if>
- <if test=' this.has("status") '> and status = #{status} </if>
- </where>
- order by
- <choose>
- <when test='sortType == 1'> id desc </when>
- <when test='sortType == 2'> item_code desc </when>
- <when test='sortType == 3'> item_name desc </when>
- <when test='sortType == 4'> price desc </when>
- <when test='sortType == 5'> need desc </when>
- <otherwise> id desc </otherwise>
- </choose>
- </select>
-
-
-
-
-
-
-
-
-
- <!-- 查 - 根据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.has("id") '> and id = #{id} </if>
- <if test=' this.has("typeId") '> and type_id = #{typeId} </if>
- <if test=' this.has("typeName") '> and type_name = #{typeName} </if>
- <if test=' this.has("itemCode") '> and item_code = #{itemCode} </if>
- <if test=' this.has("itemName") '> and item_name like concat('%', #{itemName} ,'%') </if>
- <if test=' this.has("price") '> and price = #{price} </if>
- <if test=' this.has("unit") '> and unit = #{unit} </if>
- </where>
- order by
- <choose>
- <when test='sortType == 1'> id desc </when>
- <when test='sortType == 2'> type_id desc </when>
- <when test='sortType == 3'> type_name desc </when>
- <when test='sortType == 4'> item_code desc </when>
- <when test='sortType == 5'> item_name desc </when>
- <when test='sortType == 6'> price desc </when>
- <when test='sortType == 7'> unit desc </when>
- <otherwise> id desc </otherwise>
- </choose>
- </select>
- </mapper>
|