SqlMapClientTemplate是org.springframework.orm.ibatis下的

而SqlMapClient是ibatis的

SqlMapClientTemplate是SqlMapClient的封装类. 
SqlMapClient中包含着session的管理. 
SqlMapClientTemplate用于session的封装,以及异常的捕捉. 
所以按照以上的推断来说.应该尽量使用SqlMapClientTemplate. 
保证session以及Exception的正常以及统一.

下面是两种类型在spring中的集成配置及用法:、

SqlMapClientTemplate:

1、在spring中的配置


  1. <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  2. <property name="dataSource" ref="dataSource" />
  3. <property name="configLocation">
  4. <value>classpath:/sqlmap-config.xml</value>
  5. </property>
  6. </bean>
  7. <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
  8. <property name="sqlMapClient" ref="sqlMapClient"></property>
  9. </bean>
  10. <bean id="accountDAO" class="com.raycloud.test.dao.AccountDAO">
  11. <property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"></property>
  12. </bean>

2、在dao中的实现


  1. @Repository//使用该注解相当于声明了一个bean
  2. public class AccountDAO {
  3. SqlMapClientTemplate sqlMapClientTemplate;
  4. public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
  5. this.sqlMapClientTemplate = sqlMapClientTemplate;
  6. }
  7. public Integer addAccount(Account account) throws SQLException{
  8. return (Integer)this.sqlMapClientTemplate.insert("Account.insertAccount", account);
  9. }
  10. }

SqlMapClient:

1、在spring中的配置


  1. <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  2. <property name="dataSource" ref="dataSource" />
  3. <property name="configLocation">
  4. <value>classpath:/sqlmap-config.xml</value>
  5. </property>
  6. </bean>
  7. <bean id="accountDAO" class="com.raycloud.test.dao.AccountDAO">
  8. <property name="sqlMapClient" ref="sqlMapClient"></property>
  9. </bean>

2、在dao中的实现


  1. @Repository//使用该注解相当于声明了一个bean
  2. public class AccountDAO {
  3. SqlMapClient sqlMapClient;
  4. public void setSqlMapClient(SqlMapClient sqlMapClient) {
  5. this.sqlMapClient = sqlMapClient;
  6. }
  7. public Integer addAccount(Account account) throws SQLException{
  8. return (Integer)this.sqlMapClient.insert("Account.insertAccount", account);
  9. }
  10. }

Ibatis中SqlMapClientTemplate和SqlMapClient的区别的更多相关文章

  1. ibatis中resultClass与resultMap 的区别

    ibatis的resultClass与resultMap还是有很大的区别.以下是我碰到的一个问题. 配置文件写法如下: 1 sqlMap2 typeAlias alias="notice&q ...

  2. ibatis中的$和#的区别

    介绍 在Ibatis中我们使用SqlMap进行Sql查询时需要引用参数,在参数引用中遇到的符号#和$之间的区分为,#可以进行与编译,进行类型匹配,而$不进行数据类型匹配,例如: select * fr ...

  3. ibatis 中isNull, isNotNull与isEmpty, isNotEmpty区别

    在iBATIS中isNull用于判断参数是否为Null,isNotNull相反 isEmpty判断参数是否为Null或者空,满足其中一个条件则其true isNotEmpty相反,当参数既不为Null ...

  4. ibatis中 $ 于 # 的 区别?

    转自: http://www.blogjava.net/lsbwahaha/archive/2009/04/16/266026.html 一个项目中在写ibatis中的sql语句时,where use ...

  5. ibatis 中#和 $ 符号的区别

    1.数据类型匹配 #:会进行预编译,而且进行类型匹配(自动确定数据类型): $:不进行数据类型匹配. 2.实现方式: # 用于变量替换(先生成一个占位符,然后替换) select * from use ...

  6. ibatis中的符号#跟$区别

    昨天一个项目中在写ibatis中的sql语句时,order by #field#, 运行时总是报错,后来上网查了查,才知道这里不该用#,而应该用$,随即查了下#与$的区别.  总结如下:  1.#是把 ...

  7. ibatis 中 $与#的区别

    ibatis 中 $与#的区别 使用#: select * from table where id = #id# 如果字段为整型:#id#表示成id select * from table where ...

  8. 【转】ibatis 中isNull, isNotNull与isEmpty, isNotEmpty区别

    转自:http://blog.csdn.net/fanfanjin/article/details/6676566 在iBATIS中 isNull用于判断参数是否为Null,isNotNull相反 i ...

  9. ibatis 中的 $和#的区别

    在sql配置中比如in(#rewr#) 与in ($rewr$) 在Ibatis中我们使用SqlMap进行Sql查询时需要引用参数,在参数引用中遇到的符号#和$之间的区分为,#可以进行与编译,进行类型 ...

随机推荐

  1. Cannot find ./catalina.sh The file is absent or does not have execute permission This file is needed to run this program(问题解决)

    web项目没有打成包,直接放在了linux服务器上. 进入tomcat/bin目录,执行启动的时候出现如下错误: 解决方法: 在tomcat 的bin目录下 执行这条命令chmod +x *.sh   ...

  2. MySQL之DDL数据定义语言:库、表的管理

    库的管理 常用命令 #创建库 create database if not exists 库名 [ character set 字符集名]; create database if not exists ...

  3. idea查看方法在哪里被调用

    方法一 选中方法名,右键选择Find Usages 方法二 选中方法快捷键ctrl + alt + h查看Hierarchy Callers

  4. SpringBoot 整合 Docker

    最近备忘录新加的东西倒是挺多的,但到了新环境水土不服没动力去整理笔记 1. Demo Project 首先准备一个简单的项目,用来部署到 Docker 主机上,并且能验证该项目是否成功运行 1.1 接 ...

  5. JVM 核心参数

    JVM 内存相关的几个核心参数 参数部分看我笔记   https://note.youdao.com/s/Ch3awnVu JVM模板 1. ParNew + CMS 版 根据服务调整 -Xmx -X ...

  6. flask cache

    http://brunorocha.org/python/flask/using-flask-cache.html 如何在大项目中使用cache 新建全局cache.py cache = Cache( ...

  7. java.lang.NoSuchFieldError: REFLECTION

    2020-09-14 09:13:21.415 INFO org.apache.cxf.service.factory.ReflectionServiceFactoryBean Line:457 - ...

  8. gorm框架表名自动加s问题

    查看日志会发现表名自动加了s 在model实现以下方法即可解决 type UsUser struct { ID int64 `gorm:"column:id" db:"c ...

  9. dedecms被挂马排毒的过程

    又经历了一次dedecms被挂马排毒的过程,排毒过程在这里跟大家分享一下. 挂马之后,网站的表现形式: 直接访问网站没有任何问题,从百度搜索的关键词访问网站,就跳转到另外一个网站. 根据我原来的排毒经 ...

  10. OPA-Gatekeeper实验:对特定用户的更新时间窗口做限制

    实验目的 OPA-Gatekeeper可以在Kubernetes 中,通过策略来实现一些额外的管理.安全方面的限制,例如:限制特定用户在 Namespace 中的行为权限 本次实验将在test命名空间 ...