mybatis杂记
mybatis学习官网:
1、如果项目中使用maven管理,又引用 了mybatis框架,
下面是mybatis官网给出的 mybatis在maven中央仓库的坐标原文
详情见连接:https://code.google.com/p/mybatis/wiki/DocMavenTutorial
MyBatis & Maven
The following is the Maven group, artifact and version for MyBatis.
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.1.1</version>
</dependency>
If you are looking to try the latest and greatest you can use our snapshot repository. Just add the following to your project's pom.xml or to a profile defined in your settings.xml.
<repository>
<id>mybatis-snapshot</id>
<name>MyBatis Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url></repository>
2、What is the difference between #{...} and ${...}?
MyBatis interprets #{...} as a parameter marker in a JDBC prepared statement. MyBatis interprets ${...} as string substitution. It is important to know the difference because parameter markers cannot be used in certain places in SQL statements. For example, you cannot use a parameter marker to specify a table name. Given the following code:
Map<String,Object> parms =newHashMap<String,Object>();
parms.put("table","foo");
parms.put("criteria",37);List<Object> rows = mapper.generalSelect(parms);
<selectid="generalSelect"parameterType="map">
select * from ${table} where col1 = #{criteria}
</select>
MyBatis will generate the following prepared statement:
select*from foo where col1 =?
Important: note that use of ${...} (string substitution) presents a risk for SQL injection attacks. Also, string substitution can be problematical for complex types like dates. For these reasons, we recommend using the #{...} form whenever possible.
mybatis杂记的更多相关文章
- MyBatis SpringBoot 杂记
最近接了个xxx代码. 不能说人家不好, 因为必进年月久了.能用这么长时间, 不就说明还不错么?! 我们现在每天写的, 能超出人家的么~~~ 呵呵 Java项目中, 把动态数据源切换的框架整合进来. ...
- 【分享】标准springMVC+mybatis项目maven搭建最精简教程
文章由来:公司有个实习同学需要做毕业设计,不会搭建环境,我就代劳了,顺便分享给刚入门的小伙伴,我是自学的JAVA,所以我懂的.... (大图直接观看显示很模糊,请在图片上点击右键然后在新窗口打开看) ...
- Java MyBatis 插入数据库返回主键
最近在搞一个电商系统中由于业务需求,需要在插入一条产品信息后返回产品Id,刚开始遇到一些坑,这里做下笔记,以防今后忘记. 类似下面这段代码一样获取插入后的主键 User user = new User ...
- [原创]mybatis中整合ehcache缓存框架的使用
mybatis整合ehcache缓存框架的使用 mybaits的二级缓存是mapper范围级别,除了在SqlMapConfig.xml设置二级缓存的总开关,还要在具体的mapper.xml中开启二级缓 ...
- 【SSM框架】Spring + Springmvc + Mybatis 基本框架搭建集成教程
本文将讲解SSM框架的基本搭建集成,并有一个简单demo案例 说明:1.本文暂未使用maven集成,jar包需要手动导入. 2.本文为基础教程,大神切勿见笑. 3.如果对您学习有帮助,欢迎各种转载,注 ...
- mybatis plugins实现项目【全局】读写分离
在之前的文章中讲述过数据库主从同步和通过注解来为部分方法切换数据源实现读写分离 注解实现读写分离: http://www.cnblogs.com/xiaochangwei/p/4961807.html ...
- MyBatis基础入门--知识点总结
对原生态jdbc程序的问题总结 下面是一个传统的jdbc连接oracle数据库的标准代码: public static void main(String[] args) throws Exceptio ...
- Mybatis XML配置
Mybatis常用带有禁用缓存的XML配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...
- MyBatis源码分析(一)开篇
源码学习的好处不用多说,Mybatis源码量少.逻辑简单,将写个系列文章来学习. SqlSession Mybatis的使用入口位于org.apache.ibatis.session包中的SqlSes ...
随机推荐
- ie下jquery ajax 80020101错误的解决方法
<script language="javascript"> <!-- function checkAll(name,isCheck){ ...
- moment 和ko 绑定msdate格式的日期值(静态text)
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8& ...
- Jqgrid入门-Jqgrid列数据拖动(七)
上一章提到在Jqgrid中如何设置二级表头,这一章节主要探讨Jqgrid表格里面的数据如果实现拖动功能,比如你想把第一行的数据拖到当前页的最后一行,或者其他位置. Jqgrid表格插件自己没有 ...
- hdu 4607 Park Visit(树上最长链)
求树上最长链:两遍搜索. 第一次从树上任意点开始,最远点必然是某一条最长链上的端点u. 第二次从u开始,最远点即该最长链的另一端点. 先在最长链上走,不足再去走支链. 把询问数m错打成n,狠狠wa了一 ...
- (转)TCP协议那些事
(上) TCP是一个巨复杂的协议,因为他要解决很多问题,而这些问题又带出了很多子问题和阴暗面.所以学习TCP本身是个比较痛苦的过程,但对于学习的过程却能让人有很多收获.关于TCP这个协议的细节,我还是 ...
- Hide Xcode8 strange log.
Product > Scheme > Edit Scheme Environment Variables set OS_ACTIVITY_MODE = disable
- Oracle中常见的33个等待事件小结
在Oracle 10g中的等待事件有872个,11g中等待事件1116个. 我们可以通过v$event_name 视图来查看等待事件的相关信息 一. 等待事件的相关知识 1.1 等待事件主要可 ...
- 【Mac】Mac键盘实现Home, End, Page UP, Page DOWN
* Home键=Fn+左方向 * End键=Fn+右方向 * PageUP=Fn+上方向 * PageDOWN=Fn+下方向 * 向后删除=Fn+delete * Find ...
- 【JS】js获得下拉列表选中项的值和id
function tijiao(){ var elem = document.getElementById("dish_sort"); var index=elem.selecte ...
- UVALive 5029
用字典树来查询,关键是怎么处理输入的8个数字代表的字符,把每个数分别除以0.95和1.05得到8的区间,按左区间从小到大排序,那么和第一个区间有交集的必然代表二进制0,与它没交集的之后都是1,因为题目 ...