MyBatis注意事项和相关技术点
1.万能的Map集合
mapper接口
public interface UserMapper {
User fingByName(Map<String,Object> map);
}
mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yunhe.mapper.UserMapper">
<select id="fingByName" parameterType="map" resultType="com.yunhe.pojo.User">
select * from `user` where username = #{name} and password = #{pass}
</select>
</mapper>
测试类
@Test
public void demo2() throws IOException {
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
Map<String,Object> map=new HashMap<String, Object>();
map.put("name","lisi");
map.put("pass","123");
User all = mapper.fingByName(map);
System.out.println(all);
}
2.在spring核心文件引用别的properties文件
<context:property-placeholder location="classpath:db.properties"/>
3.MyBatis执行流程图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c0bb61a369a5adc8bd29e46427f3987d.png#pic_center)