GoodDao

<?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="cn.jnu.core.dao.GoodDao" >

    <!-- 创建商品 
    <insert id="createGood" parameterType="Good" >
        insert into m_good (
            user_id, good_name, description, depreciation, good_price, good_status, good_photo
        )
        values (
            #{user_id}, 
            #{name, jdbcType=VARCHAR}, 
            #{description, jdbcType=VARCHAR}, 
            #{depreciation, jdbcType=NUMERIC},
            #{price, jdbcType=NUMERIC}, 
            #{status, jdbcType=NUMERIC}, 
            #{photo, jdbcType=VARCHAR}
        )
    </insert>
    -->
    <!-- 调用存储过程,插入商品并返回数据库中生成的id -->
    <update id="createGood" parameterType="Good" statementType="CALLABLE">
            call proc_add_good(
                #{user_id, jdbcType=NUMERIC}, 
                #{name, jdbcType=VARCHAR}, 
                #{description,jdbcType=VARCHAR}, 
                #{depreciation, jdbcType=NUMERIC},
                #{price, jdbcType=NUMERIC}, 
                #{status, jdbcType=NUMERIC}, 
                #{photo, jdbcType=NUMERIC},
                #{goods_id, mode=OUT, jdbcType=NUMERIC, javaType=Integer}
            )   
    </update>
    
    <!-- 根据id查询某件商品的信息 -->
    <select id="findById" parameterType="Integer" resultType="GoodQueryVo">
        select good_name name, description, depreciation, good_price, a.user_id seller_id, username seller
        from m_good a, m_user b
        where a.user_id = b.user_id and goods_id = #{gid}
    </select>
    
    <!-- 根据gid删除指定商品 -->
    <delete id="deleteGood" parameterType="Integer" >
        delete from m_good
        where goods_id = #{gid}
    </delete>
    
    <!-- 修改商品信息 -->
    <update id="updateGood" parameterType="Good" >
        update m_good
        <set>
            <if test="name != null and name != ''" >
                good_name = #{name},
            </if>
            <if test="description != null and description != ''" >
                description = #{description},
            </if>
            <if test="depreciation != null">
                depreciation = #{depreciation},
            </if>
            <if test="price != null">
                good_price = #{price},
            </if>
        </set>
        where goods_id = #{gid}
    </update>
    
    <!-- 商品进行搜索 -->
    <select id="findGoodList" parameterType="Map" resultType="Good" >
        select goods_id, a.user_id, good_name name, description, depreciation, good_price price, 
            good_status status, create_time createTime, good_photo photo
        from m_good a, m_user b
        <where>
            a.user_id = b.user_id
            <if test="good_name != null and good_name != ''" >
                and good_name like concat('%', concat(#{good_name}, '%'))
            </if>
            <if test="user_name != null and user_name != ''" >
                and username like concat('%', concat(#{user_name}, '%'))
            </if>
            <if test="depreciation != null" >
                and depreciation &gt;= #{depreciation}
            </if>
            <if test="price_max != null" >
                and price &lt;= #{price_max}
            </if>
            <if test="price_min != null" >
                and price &gt;= #{price_min}
            </if>
        </where>    
    </select>
</mapper>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容