根據參數名字映射 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>條件語句前面不要隨意寫註釋,否則容易報錯。