83 lines
2.9 KiB
XML
83 lines
2.9 KiB
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="ltd.qubit.survey.dao.OptionDao">
|
|
<!-- 结果映射 -->
|
|
<resultMap id="optionMap" type="ltd.qubit.survey.model.Option">
|
|
<id property="id" column="id"/>
|
|
<result property="questionId" column="question_id"/>
|
|
<result property="code" column="code"/>
|
|
<result property="content" column="content"/>
|
|
<result property="requiresText" column="requires_text"/>
|
|
<result property="createdAt" column="created_at"/>
|
|
</resultMap>
|
|
|
|
<!-- 基础列 -->
|
|
<sql id="baseColumns">
|
|
`id`, `question_id`, `code`, `content`, `requires_text`, `created_at`
|
|
</sql>
|
|
|
|
<!-- 插入 -->
|
|
<insert id="insert" parameterType="ltd.qubit.survey.model.Option" useGeneratedKeys="true" keyProperty="id">
|
|
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`)
|
|
VALUES (#{questionId}, #{code}, #{content}, #{requiresText})
|
|
</insert>
|
|
|
|
<!-- 批量插入 -->
|
|
<insert id="batchInsert" parameterType="java.util.List">
|
|
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`)
|
|
VALUES
|
|
<foreach collection="list" item="item" separator=",">
|
|
(#{item.questionId}, #{item.code}, #{item.content}, #{item.requiresText})
|
|
</foreach>
|
|
</insert>
|
|
|
|
<!-- 更新 -->
|
|
<update id="update" parameterType="ltd.qubit.survey.model.Option">
|
|
UPDATE `option`
|
|
SET `question_id` = #{questionId},
|
|
`code` = #{code},
|
|
`content` = #{content},
|
|
`requires_text` = #{requiresText}
|
|
WHERE `id` = #{id}
|
|
</update>
|
|
|
|
<!-- 删除 -->
|
|
<delete id="deleteById" parameterType="long">
|
|
DELETE FROM `option` WHERE `id` = #{id}
|
|
</delete>
|
|
|
|
<!-- 根据问题ID删除 -->
|
|
<delete id="deleteByQuestionId" parameterType="long">
|
|
DELETE FROM `option` WHERE `question_id` = #{questionId}
|
|
</delete>
|
|
|
|
<!-- 根据ID查询 -->
|
|
<select id="findById" parameterType="long" resultMap="optionMap">
|
|
SELECT <include refid="baseColumns"/>
|
|
FROM `option`
|
|
WHERE `id` = #{id}
|
|
</select>
|
|
|
|
<!-- 查询所有 -->
|
|
<select id="findAll" resultMap="optionMap">
|
|
SELECT <include refid="baseColumns"/>
|
|
FROM `option`
|
|
ORDER BY `question_id`, `code`
|
|
</select>
|
|
|
|
<!-- 根据问题ID查询 -->
|
|
<select id="findByQuestionId" parameterType="long" resultMap="optionMap">
|
|
SELECT <include refid="baseColumns"/>
|
|
FROM `option`
|
|
WHERE `question_id` = #{questionId}
|
|
ORDER BY `code`
|
|
</select>
|
|
|
|
<!-- 根据问题ID和选项代码查询 -->
|
|
<select id="findByQuestionIdAndCode" resultMap="optionMap">
|
|
SELECT <include refid="baseColumns"/>
|
|
FROM `option`
|
|
WHERE `question_id` = #{questionId}
|
|
AND `code` = #{code}
|
|
</select>
|
|
</mapper> |