mybatis dao層到xml映射文件正確的傳參數方式

根據參數名字映射
public interface UserDao extends BaseMapper<User>
{

     List<User> listUser(@Param("userName") String userName,@Param("password") String password);
}

根據@Param("userName") 中的名稱與xml映射文件的#{userName}名稱對應,此時在select中可以不用寫paramType

<select id="listUser" resultType="com.reuse.customer.entity.User" >
    select * from user
     <where>
         <if test="userName!=null and userName.trim()!=''">
             user_name=#{userName}
         </if>
         <if test="password!=null and password.trim()!=''">
             and password=#{password}
         </if>
     </where>
</select>

注意在<where>條件語句前面不要隨意寫註釋,否則容易報錯。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章