查询语句是 MyBatis 中最常用的元素之一,光能把数据存到数据库中价值并不大,只有还能重新取出来才有用,多数应用也都是查询比修改要频繁。对每个插入、更新或删除操作,通常间隔多个查询操作。这是 MyBatis 的基本原则之一,也是将焦点和努力放在查询和结果映射的原因。简单查询的 select 元素是非常简单的。比如:
学习工具 mybatis 文档 基本上我们能用到的使用方法,包括spring / 非spring的各种用法,同样对于英文不太好的同学,也有中文文档可以选择 http://www.mybatis.org/mybatis -3/getting-started.html http://www.mybatis.org/mybatis-3/zh/index.html (中文) mybatis源码 项目在github上开源,都可以公开访问 https://github.com/mybatis/mybatis-3 idea 目前java主流开发ide 小刀的微信群 一个人学习很辛苦,这里有小伙伴陪你一起学 用idea拉取源码 小刀fork 了一份mybatis的源码,同时写补充一些注释进去 https://github.com/weixiaodexiaoxiaodao/mybatis-3 可以选择先下载下来再导入,或者直接用idea下载,
Default: false for select statements. https://mybatis.org/mybatis-3/sqlmap-xml.html#select 其中:onfiguration.getLocalCacheScope () 为LocalCacheScope.SESSION,见配置: https://mybatis.org/mybatis-3/configuration.html#settings 即:默认情况下查询前和后都不会清空一级缓存 CacheKey, so it may be quite difficult (if possible) to add such option https://github.com/mybatis/mybatis 开启二级缓存配置: 1、settings中配置:cacheEnabled 为true(默认true),为二级缓存第一层全局开关 https://mybatis.org/mybatis-3/configuration.html 2、Mapper配置文件中配置:<cache/>,为二级缓存第二层开关 https://mybatis.org/mybatis-3/sqlmap-xml.html#cache <cache eviction
详见官方文档: https://mybatis.org/mybatis-3/zh/configuration.html#settings <settings> <setting name="属性" 详见官方文档: https://mybatis.org/mybatis-3/zh/configuration.html#typeAliases MyBatis有一些默认别名,如: String的别名是string
xml配置文件,可用MyBatis自己定义的数据类型,引自:http://www.mybatis.org/mybatis-3/configuration.html Associated JDBC type = #{companyid, jdbcType=BIGINT} </select> 对于jdbcType,MyBatis的API文档有说明,引自:http://www.mybatis.org/mybatis
org.apache.ibatis.logging.LogFactory.useCommonsLogging(); org.apache.ibatis.logging.LogFactory.useStdOutLogging(); 参考文档: http://www.mybatis.org/mybatis article/details/22931341 https://my.oschina.net/pingpangkuangmo/blog/410224 http://www.mybatis.org/mybatis
xml配置文件,可用MyBatis自己定义的数据类型,引自:http://www.mybatis.org/mybatis-3/configuration.html Associated JDBC type = #{companyid, jdbcType=BIGINT} </select> 对于jdbcType,MyBatis的API文档有说明,引自:http://www.mybatis.org/mybatis
c) 中文网址: http://www.mybatis.org/mybatis-3/zh/getting-start ed.html d) MyBatis 各版本下载地址: https://github.com /mybatis/mybatis-3/releases ---- MyBatis 是支持普通 SQL 查询, 存储过程和高级映射的优秀持久层框架。
artifactId> <version>3.5.2</version> </dependency> Github:https://github.com/mybatis/mybatis -3/releases 中文文档:https://mybatis.org/mybatis-3/zh/index.html 1.2 持久层 数据持久化 持久化就是将程序的数据在持久状态和瞬时状态转化的过程
源码:https://github.com/mybatis/mybatis-3 一.官方 (1)Mybatis官方文档中文版 (2)MyBatis 从入门到精通 书中指定的网络资源 (3)MyBatis
参考资料 Mybatis官方文档: https://mybatis.org/mybatis-3/ Mybatis GitHub Repository: https://github.com/mybatis /mybatis-3 Blog: Understanding Mybatis: A deep dive into its internals.
e.getMessage()); } } 代码样例见:https://github.com/f304646673/mybatis_demo.git 参考资料 https://mybatis.org/mybatis -3/zh_CN/configuration.html https://mybatis.org/mybatis-3/zh_CN/sqlmap-xml.html
学习资源: 《MyBatis从入门到精通》 MyBatis官方文档: https://mybatis.org/mybatis-3/ 动态SQL if、choose、where、set 学习资源: 《MyBatis从入门到精通》 MyBatis动态SQL官方文档: https://mybatis.org/mybatis-3/dynamic-sql.html 缓存机制 学习资源: 《MyBatis从入门到精通》 MyBatis缓存官方文档: https://mybatis.org/mybatis-3/caching.html 第四阶段:SSM框架整合与项目实战
details/49474557 今天,主要向大家分享下如何从头搭建一个最简单的mybatis项目 下载地址 Mybatis3 最新下载地址:https://github.com/mybatis/mybatis 更多细节参看mybatis官方文档:http://mybatis.github.io/mybatis-3/
objectWrapperFactory reflectorFactory plugins environments databaseIdProvider mappers 参考资料 https://mybatis.org/mybatis -3/zh_CN/configuration.html https://mybatis.org/mybatis-3/zh_CN/sqlmap-xml.html
select XXXXX from table order by "column" "desc" 主要还是对MyBatis传参形式不了解,官方介绍, P.S. https://mybatis.org/mybatis 参考资料, https://mybatis.org/mybatis-3/sqlmap-xml.html#Parameters https://www.cnblogs.com/yang82/p/7813549
中文文档:https://mybatis.org/mybatis-3/zh/dynamic-sql.html 1.如果不使用where标签 如果没用where标签的话,我们在写动态sql的时候可能需要这样
mybatis3.2.7有一个bug,使用log4j2 (2.0.2)版本时,会找不到类 ,导致启动失败,详见 https://github.com/mybatis/mybatis-3/issues/235 但没过多久 , 3.2.8就已经修复了这个bug , 最新的mybatis3.2.8下载地址为: https://github.com/mybatis/mybatis-3/releases mybatis
= connection.prepareStatement(sql); ps.setInt(1, id); 因此#{}可以有效防止SQL注入,详细可参考http://www.mybatis.org/mybatis * FROM user WHERE name LIKE #{pattern} </select> <bind>语句内部的值为OGNL表达式,具体可参考http://www.mybatis.org/mybatis open="(" separator="," close=")"> #{name} </foreach> </select> 具体可参考http://www.mybatis.org/mybatis
中文文档:https://mybatis.org/mybatis-3/zh/dynamic-sql.html 用于动态更新语句的类似解决方案叫做 set。