万能Map
//万能的Map
int addUser2(Map<String,Object> map);
<!--对象中的属性,可以直接取出来 传递map的key-->
<insert id="addUser" parameterType="map">
insert into mybatis.user (id, name,pwd) values (#{id},#{name},#{pwd});
</insert>
@Test
public void addUser2(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id",5);
map.put("name","王五");
map.put("pwd","2222333");
mapper.addUser2(map);
sqlSession.commit();
sqlSession.close();
}
Java代码执行的时候,传递通配符 % %
List<User> userList = mapper.getUserLike("%李%");
在sql拼接中使用通配符
select * from mybatis.user where name like "%"#{value}"%"
|