MyBatis,QuestionMapper.xml

<?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.ylm.exam.dao.QuestionDAO">
    <!--<cache type="com.ylm.day.util.RedisCache"/>-->
    <resultMap id="questionMap" type="com.ylm.exam.entity.Question">
        <id column="que_id" property="id"></id>
        <result column="que_content" property="content"></result>
        <result column="que_answer" property="answer"></result>
    </resultMap>

    <resultMap id="questionDetailMap" extends="questionMap" type="com.ylm.exam.entity.Question">
        <association property="type" column="type_id" select="com.ylm.exam.dao.QuestionTypeDAO.selectTypeById"></association>
        <collection property="optionList" column="que_id" select="com.ylm.exam.dao.OptionDAO.selectAllByQuestionId"></collection>
        <collection property="signList" column="que_id" select="com.ylm.exam.dao.SignDAO.selectAllByQuestionId"></collection>
    </resultMap>

    <sql id="selectColumns">
         que_id, type_id, que_content, que_answer
    </sql>

    <select id="findAll" resultMap="questionMap">
        SELECT
        <include refid="selectColumns"></include>
        FROM question
        limit #{f}, #{m}
    </select>

    <select id="findById" resultMap="questionDetailMap">
        SELECT
        <include refid="selectColumns"></include>
        FROM question
        WHERE que_id = #{id}
    </select>
    
    <select id="findBookByTypeId" resultMap="bookMap">
        SELECT book_id,book_name,book_author,update_time,type_id FROM book
        <where>
            <if test="typeId != 0">
                type_id = #{typeId}
            </if>
        </where>
        limit #{f},#{m}
    </select>

    <select id="findCountByTypeId" resultType="java.lang.Integer">
        SELECT count(1) FROM book
        <where>
            <if test="typeId != 0">
                type_id = #{typeId}
            </if>
        </where>
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO question(type_id, que_content, que_answer)
        VALUES (#{typeId}, #{content}, #{answerStr})
    </insert>

    <select id="findCondition" resultMap="employeeMap">
        SELECT id, name, email, phone, money, dept_id FROM employee
        <where>
            <if test="name != null">
                AND name LIKE #{name}"%"
            </if>
            <if test="email != null">
                AND email = #{email}
            </if>
            <if test="phone != null">
                OR phone = #{phone}
            </if>
            <if test="money != null">
                OR money = #{money}
            </if>
        </where>
    </select>

    <update id="updateSelective">
        UPDATE employee
        <set>
            <if test="name != null">
                name = #{name},
            </if>
            <if test="email != null">
                email = #{email},
            </if>
            <if test="phone != null">
                phone = #{phone},
            </if>
            <if test="money != null">
                money = #{money},
            </if>
            <if test="department != null and department.id != null">
                dept_id = #{department.id},
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <insert id="insertSelective">
        INSERT INTO employee
        <trim prefix="(" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="email != null">
                email,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="money != null">
                money,
            </if>
            <if test="department != null and department.id != null">
                dept_id,
            </if>
        </trim>
        <trim prefix=") VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="email != null">
                #{email},
            </if>
            <if test="phone != null">
                #{phone},
            </if>
            <if test="money != null">
                #{money},
            </if>
            <if test="department != null and department.id != null">
                #{department.id},
            </if>
        </trim>
    </insert>

    <select id="selectByIds" resultMap="employeeMap">
        SELECT * FROM employee WHERE id in
        <foreach collection="list" item="emp" open="(" close=")" separator=",">
            #{emp.id}
        </foreach>
    </select>
</mapper>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值