mybatis
2025-08-26 22:29:59 0 举报
AI智能生成
mybatis学习
作者其他创作
大纲/内容
java对象读取mybatis.xml配置文件
加载核心配置文件:InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
获得sqlSession工厂对象:SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
获得sqlSession对象:SqlSession sqlSession = sqlSessionFactory.openSession();
获得MyBatis框架生成的XXXMapper接口的实现类:UserMapper mapper = sqlSession.getMapper(UserMapper.class);
mybatis.xml
加载外部配置文件:properties
配置:settings
别名:typeAliases
单个创建别名:typeAlias
批量创建别名:package
类型处理器:typeHandlers
MyBatis 的拦截器插件:plugins
环境:environments
mappers标签读取mapper.xml文件
XXXMapper.xml
增删改查标签
<select>
<insert>
update
delete
动态 SQL 标签
<if>
<where>
<set>
<trim>
<foreach>
<choose>/<when>/<otherwise>
复用标签
sql
include
结果映射标签
<resultMap>
association
collection
缓存配置标签
cache
cache-ref
JDBC.properties
0 条评论
下一页