1. 程式人生 > >mybatis 常用語法記錄

mybatis 常用語法記錄

​
public List<Group> getUserRoleRelByUserUuid(@Param("groupUuid") String userUuid,@Param("roleList")List<String> roleUuidList);
/* choose when otherwise */
SELECT * from user_role where groupUuid=#{groupUuid}
    <choose>
        <when test="roleList!=null&amp;&amp;roleList.size()&gt;0">
            AND roleUuid IN
            <foreach collection="roleList" index="index" item="roleUuid" open="(" separator="," close=")">
                #{roleUuid}
            </foreach>
        </when>
        <otherwise>
            AND roleUuid IN ('')
        </otherwise>
    </choose>
​
public int getOrderCountByParams(Map<String, Object> params);
/*判斷字串相等*/
<select id="getOrderCountByParams" resultType="java.lang.Integer"  parameterType="Object">
    SELECT count(*) FROM itil_publish_order where 1=1
       <if test="timeType == '1'.toString()" >
            AND create_time &gt;= #{timeStr}
        </if>
        <if test="timeType == '2'.toString()" >
            AND end_time &lt;= #{timeStr}
        </if>
  </select>
或者
<if test = 'timeType== "1"'> </if>
/*CONCAT函式實現 模糊匹配*/
<select id="getMaxSerialCode" resultType="java.lang.String"  parameterType="Object">
        SELECT count(*) FROM
        itil_publish_order
        WHERE serial_code LIKE CONCAT('%',#{codeStr},'%')
        ORDER BY serial_code DESC LIMIT 1
</select>
​