mybatis学习04:Map和模糊查询
-
万能Map:
-
假设,我们的实体类,或者数据库中的表,字段或者参数过多,我们应当考虑使用Map!
-
Map传递参数,直接在SQL中取出key即可;parameterType="map"
-
对象传递参数,直接在SQL中取对象的属性即可!parameterType="Object"
-
只有一个基本类型的参数的情况下,可以直接在SQL中取到!parameterType="int"(可以省略)
-
多个参数用Map,或者注解!
//万能Map
int addUser2(Map<String,Object> map); -
Mapper.xml
<!--
传递map的key
-->
<insert id="addUser2" parameterType="map">
insert into mybatis.user(id, name, pwd) value (#{userId},#{userName},#{password})
</insert> -
Test
-
-
模糊查询:
-
1,Java代码执行的时候,传递通配符: %
map.put("userName","%demo%");select * from mybatis.user where name like #{userName} -
2,在SQL拼接中使用通配符:%
map.put("userName","demo");select * from mybatis.user where name like "%"#{userName}"%"
-

浙公网安备 33010602011771号