Map
- 在UserDao接口中
int AddUser2(Map<String, Object> map);
- UserMapper.xml
<insert id="AddUser2" parameterType="map">
insert into user.use1(id,name,pwd) values (#{UserId},#{UserName},#{password});
</insert>
- 测试类
public void AddUser2() {
SqlSession sqlSession = MybatisUtil.getSqlSession();
UserDao mapper = sqlSession.getMapper(UserDao.class);
Map<String, Object> map = new HashMap<String,Object>();
map.put("UserId","6");
map.put("UserName","hello");
map.put("password","hello");
mapper.AddUser2(map);
sqlSession.commit(); //涉及增删改,必须要提交事务
sqlSession.close();
}
map传递参数,在sql中直接取出key
对象传递参数,在sql中直接取出属性
只有一个基本类型参数情况下,可以直接取出
模糊查询
- java代码执行的时候传递通配符% %
select * from user.use1 where name like #{value};
List<User> user = mapper.getUserLike("%u%");
- 字符串拼接
select * from user.use1 where name like "%"#{value}"%";
List<User> user = mapper.getUserLike("u");
标签:mapper,Map,模糊,sqlSession,查询,map,user,use1
From: https://www.cnblogs.com/solutide/p/17860093.html