mybatis入門截圖三
阿新 • • 發佈:2017-09-04
style result span parameter jpg log class es2017 mybatis
-----------------------------------------------
<!-- 用戶信息的綜合查詢 --> <select id="userlist" parameterType="org.mybatis.po.UserQueryVo" resultType="org.mybatis.po.UserCustom"> <!-- 原來的sql --> <!-- select *from user where user.sex=#{userCustom.sex} and user.username like ‘%${userCustom.username}%‘ --> <!-- 動態sql --> select*from user <where> <if test="userCustom!=null"> <if test="userCustom.sex!=null and userCustom.sex!=‘‘"> and user.sex=#{userCustom.sex} </if> <if test="userCustom.username!=null and userCustom.username!=‘‘"> and user.username=#{userCustom.username} </if> </if> </where> </select>
這樣在傳入參數時,傳遞null 也不會報錯。
mybatis入門截圖三