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>条件语句前面不要随意写注释,否则容易报错。

 

 

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