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 ...
随机推荐
- 解决hibernate向mysql插入中文乱码问题
一.mysql的问题解决 MySQL会出现中文乱码的原因不外乎下列几点: 1.server本身设定问题,例如还停留在latin1 2.table的语系设定问题(包含character与coll ...
- phonegap archive 报错 Cordova/CDVViewController.h' file not found
在BuildSettings->Header Search Paths 增加如下路径,问题解决 $(OBJROOT)/UninstalledProducts/include "$(O ...
- 数学语言和程序语言的对比:面向过程与面向集合&命题
共同之处:都使用字符串或数值来引用一个客观实体.当然数字和字符串也可以作为实体对象,这取决于人的解释. 不同之处:数学语句每一行都给出了一个结论, 程序语句的每一行都定义了一个过程.注意这里所指的程序 ...
- uestc 1721 吴神,人类的希望
// 将n个相同的球放进m个盒子 盒子不为空的方法总数// dp[i][j] 表示i个盒子 j个球的方法总数// 递推关系 dp[i][j]=dp[i-1][j-1]+d[i][j-i]// a. i ...
- 【转】traits技术及模板偏特化
#include <iostream> using namespace std; struct __xtrue_type { }; // define two mark-type stru ...
- winscp配置
WinSCP Install and run WinSCP Go to Preferences (Ctrl+Alt+P) and click on Transfer, then on Add. Nam ...
- html在图片上实现下雨效果
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 前言:关于nagios监控
前言,关于nagios监控. 这段时间一直在做关于nagios监控,不停的做实验,从而也忽略了书写这方面,今天写一份安装文档花了四个多小时,看来写文档也是一件很麻烦的事情,不过,做过的事情还是需要留下 ...
- bzoj 1109 [POI2007]堆积木Klo(LIS)
[题意] n个数的序列,删除一个数后序列左移,求最后满足i==a[i]的最大个数. [思路] 设最终得到a[i]==i的序列为s,则s应满足: i<j,a[i]<a[j],i-a[i]&l ...
- bzoj4578: [Usaco2016 OPen]Splitting the Field
2365: Splitting the Field 题意:n个点,求用两个矩形面积覆盖完所有点和一个矩形覆盖完少多少面积 思路:枚举两个矩形的分割线,也就是把所有点分成两个部分,枚举分割点:先预处理每 ...