Mybatis Day03
Mybatis映射文件获取参数
#{}就是占位符赋值,${}就是字符串拼接
-
单一条件,用#{}和 ∗ ∗ 注意 {} **注意 ∗∗注意{}加单引号**
<select id="getUserByName" resultType="User"> select * from t_user where username = #{asd} </select>
-
多个条件,使用接口的方法传参数时,mybatis封装一个map,自动将传过来的参数放在一个map<arg0,传过来的参数>集合中
<select id="checkUserByNamePass" resultType="User"> select * from t_user where username = #{arg0} and password = #{arg1} </select>
- 用arg0 arg1。。arg0 arg1。。param1。。param2。。为键,以参数为值,用#{arg0} #{arg1}。。。${arg0} ${arg1}访问值,param同理
-
多条件,使用接口的方法传参数时,参数是map,我们可以自己将键值放在map里面,然后把map<k,v>集合传过去,sql参数里面是放键去访问值
<select id="checkUserByMap" resultType="User"> select * from t_user where username = #{key} and password = #{key} </select>
-
多条件,使用接口的方法传参数时,参数是实体类对象,将对象传过去,将对象的属性(有set get方法)拼接到sql中
<select id="checkLoginByParam" resultType="User"> select * from t_user where username = #{属性名} and password = #{属性名} </select>
- Mapper接口的参数为实体类时,用#{}和KaTeX parse error: Expected 'EOF', got '#' at position 6: {}访问,#̲{属性名}和{属性名}作为键访问值
-
多条件,使用接口的方法传参数时,mybatis自动封装一个map,注解@Param的vlue作为map的key,传的参数作为map的value
- 用注解的value去访问值
User checkLoginByParam(@Param("username") String username, @Param("password") String password);