9.1Mybatis的体系结构
sqlSessionFactory 单个数据库映射关系经过编译后内存镜像,
// 初始化mybatis,创建SqlSessionFactory类的实例
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
.build(inputStream);
每一个MyBatis应用都以一个sqlSessionFactory 对象的实例为核心,一旦被创建,应用执行期间都应该存在,建议使用单例模式
sqlSession 执行持久化操作的对象 单线程对象,线程不安全
9.2深入Mybatis配置文件
mybatis-config.xml
sqlsessionFactory就是根据该配置文件创建的
mabatis-config.xml文件中可以配置多个environments属性,即多个数据库连接属性。
但是每个sqlSessionFactory只能对应一个数据库。8
selectOne
selectList
selectMap
9.3深入Mapper XML映射文件
ResultMaps 最最重要强大的元素
告诉Mybatis将结果集转换成开发者所需要的对象
第9章 Mybatis的基本用法.note
conetextConfigLocation
contextConfigLocation
如果这里没有,url为/时,直接去到index.jsp了
type Status report
message /hrmweb/main
description The requested resource is not available.
有时
type Status report
message /hrmweb/loginForm
description The requested resource is not available.
request info
requestURL—>http://localhost:8080/hrmapp/main
requestContextPath—>/hrmapp
servletPath—>/main
going to forward to loginForm.jsp
request info
requestURL—>http://localhost:8080/hrmapp/loginForm
requestContextPath—>/hrmapp
servletPath—>/loginForm
visiting /loginForm,/login,/404.html….
return-flag-1=true
return-flag-3=true
return-flag-2=false
request info
requestURL—>http://localhost:8080/hrmapp/favicon.ico
requestContextPath—>/hrmapp
servletPath—>/favicon.ico
going to forward to loginForm.jsp
request info
requestURL—>http://localhost:8080/hrmapp/loginForm
requestContextPath—>/hrmapp
servletPath—>/loginForm
visiting /loginForm,/login,/404.html….
return-flag-1=true
return-flag-3=true
return-flag-2=false
request info
requestURL—>http://localhost:8080/hrmweb/main
requestContextPath—>/hrmweb
servletPath—>/main
going to forward to loginForm.jsp
request info
requestURL—>http://localhost:8080/hrmweb/loginForm
requestContextPath—>/hrmweb
servletPath—>/loginForm
visiting /loginForm,/login,/404.html….
return-flag-1=true
return-flag-3=true
return-flag-2=false