zoukankan      html  css  js  c++  java
  • select

    1.String 参数 作为if 条件

    mybatis mapper.xml sql  当parameterType为String时 任何参数都必须为_parameter(比如原先为参数为key),若果没有_parameter,提示错误There is no getter of  'username' in java.lang.string

    int pagingCount(String key);
    
    <select id="pagingCount" resultType="int" parameterType="string">
             SELECT 
                count(1)
            FROM 
                users 
            WHERE 1=1
            <if test="key != null and '' != key">
                name = #{key} or username = #{key}
            </if>
         </select>
    <select id="pagingCount" resultType="int" parameterType="string">
             SELECT 
                count(1)
            FROM 
                users 
            WHERE 1=1
            <if test="_parameter != null and '' != _parameter">
                and name = #{_parameter} or username = #{_parameter}
            </if>
         </select>

     2. list 作为必须条件,otherwise 直接返回false ,结果集返回null

    List<Role> queryRolesByOrgIds(@Param("ids") Set<Integer> ids);
    <select id="queryRolesByOrgIds" resultMap="roleMap" parameterType="list" >
          select r.id,r.name,r.code,r.app_code,r.parent_id from ts_role r
              join tm_org_role ro
              on r.id = ro.role_id
          where
          <choose>
              <when test="ids!=null and ids.size>0">
                  ro.org_id in
                  <foreach collection="ids" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
              </when>
              <otherwise>
                  false
              </otherwise>
          </choose>
      </select>
  • 相关阅读:
    leetcode刷题总结401-450
    leetcode刷题总结351-400
    马哥博客作业第六周
    马哥教育第一阶段考试
    马哥博客作业第四周
    马哥博客作业第三周
    马哥博客作业第二周
    马哥博客作业第一周
    马哥博客预习作业第三周
    马哥博客预习作业第二周
  • 原文地址:https://www.cnblogs.com/yangfei-beijing/p/8529015.html
Copyright © 2011-2022 走看看