为了使查询数据库时,可以使用命名参数,则要用NamedParameterJdbcTemplate

1.Java文件配置

 @Bean
public NamedParameterJdbcTemplate jdbcTemplate(DataSource dataSource) {
return new NamedParameterJdbcTemplate(dataSource);
}

2.在Dao层中使用

 private static final String INSERT_SPITTER =
"insert into Spitter " +
" (username, password, fullname, email, updateByEmail) " +
"values " +
" (:username, :password, :fullname, :email, :updateByEmail)"; public void addSpitter(Spitter spitter) {
Map < String, Object > paramMap = new HashMap < String, Object > ();
paramMap.put("username", spitter.getUsername());
paramMap.put("password", spitter.getPassword());
paramMap.put("fullname", spitter.getFullName());
paramMap.put("email", spitter.getEmail());
paramMap.put("updateByEmail", spitter.isUpdateByEmail());
jdbcOperations.update(INSERT_SPITTER, paramMap);
}

SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-004-使用NamedParameterJdbcTemplate的更多相关文章

  1. SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-003-四种方式获取DataSource

    一.概述 1.Spring offers several options for configuring data-source beans in your Spring application, i ...

  2. SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-001-Spring对原始JDBC的封装

    1.spring扩展的jdbc异常 2.Template的运行机制 Spring separates the fixed and variable parts of the data-access p ...

  3. SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-002-本章的源代码

    0.结构 一.JDBC层 1. package spittr.db; import java.util.List; import spittr.domain.Spitter; /** * Reposi ...

  4. SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-005- 异常处理@ResponseStatus、@ExceptionHandler、@ControllerAdvice

    No matter what happens, good or bad, the outcome of a servlet request is a servlet response. If an e ...

  5. SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-002- Spring的JSP标签之form标签(<sf:input><sf:errors><sf:form>)

    一. Spring offers two JSP tag libraries to help define the view of your Spring MVC web views. One tag ...

  6. SPRING IN ACTION 第4版笔记-第五章BUILDING SPRING WEB APPLICATIONS-007-表单验证@Valid、Error

    一. Starting with Spring 3.0, Spring supports the Java Validation API in Spring MVC . No extra config ...

  7. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-003-Spring对AOP支持情况的介绍

    一. 不同的Aop框架在支持aspect何时.如何织入到目标中是不一样的.如AspectJ和Jboss支持在构造函数和field被修改时织入,但spring不支持,spring只支持一般method的 ...

  8. SPRING IN ACTION 第4版笔记-第一章-005-Bean的生命周期

    一. 1. As you can see, a bean factory performs several setup steps before a bean is ready touse. Let’ ...

  9. Spring In Action 第4版笔记-第一章-001架构

    1.Spring’s fundamental mission: Spring simplifies Java development. 2.To back up its attack on Java ...

随机推荐

  1. Jquery Mobile局部刷新后js和css失效,需局部渲染

    $(function () {    $("#submit").click(function(){      var storage = window.localStorage;  ...

  2. OpenGl学习笔记3之模型变换、视图变换、投影变换、视口变换介绍

    模型变换.视图变换.投影变换.视口变换介绍 opengl中存在四种变换,分别是模型变换,视图变换,投影变换,视口变换.这四种变换是图形渲染的基本操作,实质上这四种变换都是由矩阵乘法表示(这些操作都是由 ...

  3. P3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队

    太水了,背包DP. (转载请注明出处:http://www.cnblogs.com/Kalenda/) ; var n,f,i,j,ans,t,tt:longint; q:array[..] of l ...

  4. Spring集成hibernate错误

    八月 25, 2016 7:55:31 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule ...

  5. [转载]linux sed命令详解

    简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的 ...

  6. curl Protocol 'http not supported or disabled in libcurl

    C:\Documents and Settings\ganiks.liu\Desktop\curl-7.37.0-win32\bin>curl -V curl 7.37.0 (i386-pc-w ...

  7. Entity Framework公共的增删改方法

    using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.I ...

  8. 生成中文版JavaDoc

    RT. 在用IDEA生成中文版JavaDoc时,出现如下问题: java.lang.IllegalArgumentException at sun.net.www.ParseUtil.decode(P ...

  9. SQLSERVER中WITH(NOLOCK)详解

    在查询语句中使用 NOLOCK 和 READPAST 处理一个数据库死锁的异常时候,其中一个建议就是使用 NOLOCK 或者 READPAST .有关 NOLOCK 和 READPAST的一些技术知识 ...

  10. 引擎设计跟踪(九.14.2e) DelayLoaded DLLs (/DELAYLOAD)

    关于DLL的delay load: http://msdn.microsoft.com/en-us/library/151kt790.aspx 最近在做GLES的shader compiler, 把现 ...