1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?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_goods.TbGoodsMapper">
- <!-- 增 [G] -->
- <insert id="add">
- insert into
- tb_goods (id, code, name, status, create_time)
- values (#{id}, #{code}, #{name}, #{status}, now())
- </insert>
- <!-- 删 -->
- <delete id="delete">
- delete from tb_goods
- where id = #{id}
- </delete>
- <!-- 改 [G] -->
- <update id="update">
- update tb_goods set
- id = #{id},
- code = #{code},
- name = #{name},
- status = #{status},
- create_time = #{createTime}
- where id = #{id}
- </update>
- <!-- ================================== 查询相关 ================================== -->
-
- <!-- 通用映射:手动模式 -->
- <resultMap id="model" type="com.pj.project.tb_goods.TbGoods">
- <result property="id" column="id" />
- <result property="code" column="code" />
- <result property="name" column="name" />
- <result property="status" column="status" />
- <result property="createTime" column="create_time" />
- </resultMap>
-
- <!-- 公共查询sql片段 -->
- <sql id="select_sql">
- select *
- from tb_goods
- </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("code") '> and code like concat('%', #{code},'%') </if>
- <if test=' this.has("name") '> and name like concat('%', #{name},'%')</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'> code desc </when>
- <when test='sortType == 3'> name desc </when>
- <when test='sortType == 4'> status desc </when>
- <when test='sortType == 5'> create_time desc </when>
- <otherwise> id asc </otherwise>
- </choose>
- </select>
-
-
-
-
-
-
-
-
-
- </mapper>
|