mybatis xml格式

like条件查询

<select id="queryListByCondition" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from e_user
    <where>
      status = '0'
      <if test="username != null and username != ''">
        and username like concat("%",#{username},"%")
      </if>
      <if test="phone != null and mobile !=''">
        and phone like concat("%",#{phone},"%")
      </if>
    </where>
  </select>

in () 用法

<!--根据所选的知识点数组 随机查询10题 -->
  <select id="queryListByPointIds" resultType="com.youruan.examine.entity.vo.EQuestionVo">
    select DISTINCT t.name as questionType,ques.* from e_question ques
    LEFT JOIN e_question_type t on ques.question_type_id = t.id
    LEFT JOIN e_question_point p on p. question_id = ques.id
    <where>
      1=1
      <if test="pointIds != null and pointIds.size>0">
        AND p.point_id in
        <foreach collection="pointIds" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
    </where>
    ORDER BY RAND() LIMIT 10
  </select>

java传参

private List<Integer> pointIds;

统计查询

<!--根据用户id查询历史记录中id最大的 id-->
  <select id="selectMaxQuesId" resultType="java.lang.Integer">
    select  max(question_id) as quesId from e_user_question_history
    where user_id = #{userId } and status = 3
  </select>

大于小于符号判断

<!--根据主键id查询上一题-->
  <select id="queryBackQuestion" resultType="com.youruan.examine.entity.vo.EQuestionVo">
    select  ques.*,t.name as questionType from e_question ques
    LEFT JOIN e_question_type t on ques.question_type_id = t.id
    where ques.id =
    ( select max(id) from e_question where id &lt; #{id } )
  </select>

< 应写为 。。。

在这里插入图片描述

update 用法

<update id="updateOrgNamebyOrgId" >
    update staff set org_name = null where org_id = #{orgId}

  </update>

delete用法

<!-- 根据 表格id 删除数据 -->
  <delete id="delByFormId" parameterType="int">
    delete from customized where
    form_id = #{formId}
  </delete>

根据主键id查询下一题

<select id="selectMaxQuesId" resultType="java.lang.Integer">
  select  max(user_question_hist_id) as quesId from e_user_question_history
  where user_id = #{userId } and status = 3
</select>

版权声明:本文为qq_36460397原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
THE END
< <上一篇
下一篇>>