一起来学 SpringBoot 2.x | 第五篇:使用 JdbcTemplate 访问数据库

Spring Boot多数据源(JdbcTemplate)配置与使用 https://blog.csdn.net/u012081441/article/details/80746538 立即下载

点击上方“芋道源码”,选择“置顶公众号”

技术文章第一时间送达!

源码精品专栏

 

摘要: 原创出处 http://blog.battcn.com/2018/05/07/springboot/v2-orm-jdbc/ 「唐亚峰」欢迎转载,保留摘要,谢谢!

  • 导入依赖

  • 连接数据库

  • 具体编码

  • 表结构

  • 实体类

  • restful 风格接口

  • 测试

  • 总结

  • 说点什么


SpringBoot 是为了简化 Spring 应用的创建、运行、调试、部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖就可以轻易的搭建出一个 WEB 工程

Spring Framework对数据库的操作在JDBC上面做了深层次的封装,通过依赖注入功能,可以将 DataSource 注册到JdbcTemplate之中,使我们可以轻易的完成对象关系映射,并有助于规避常见的错误,在SpringBoot中我们可以很轻松的使用它。

特点

  • 速度快,对比其它的ORM框架而言,JDBC的方式无异于是最快的

  • 配置简单,Spring自家出品,几乎没有额外配置

  • 学习成本低,毕竟JDBC是基础知识,JdbcTemplate更像是一个DBUtils

导入依赖

在 pom.xml 中添加对 JdbcTemplate 的依赖

<!-- Spring JDBC 的依赖包,使用 spring-boot-starter-jdbc 或 spring-boot-starter-data-jpa 将会自动获得HikariCP依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- MYSQL包 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 默认就内嵌了Tomcat 容器,如需要更换容器也极其简单-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

连接数据库

在application.properties中添加如下配置。值得注意的是,SpringBoot默认会自动配置DataSource,它将优先采用HikariCP连接池,如果没有该依赖的情况则选取tomcat-jdbc,如果前两者都不可用最后选取Commons DBCP2。通过spring.datasource.type属性可以指定其它种类的连接池

spring.datasource.url=jdbc:mysql://localhost:3306/chapter4?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
spring.datasource.password=root
spring.datasource.username=root
#spring.datasource.type
#更多细微的配置可以通过下列前缀进行调整
#spring.datasource.hikari
#spring.datasource.tomcat
#spring.datasource.dbcp2

启动项目,通过日志,可以看到默认情况下注入的是HikariDataSource

2018-05-07 10:33:54.021  INFO 9640 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-05-07 10:33:54.026  INFO 9640 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-05-07 10:33:54.071  INFO 9640 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-05-07 10:33:54.075  INFO 9640 --- [           main] com.battcn.Chapter4Application           : Started Chapter4Application in 3.402 seconds (JVM running for 3.93)

具体编码

完成基本配置后,接下来进行具体的编码操作。为了减少代码量,就不写UserDao、UserService之类的接口了,将直接在Controller中使用JdbcTemplate进行访问数据库操作,这点是不规范的,各位别学我…

表结构

创建一张 t_user 的表

CREATE TABLE `t_user` (
  `id` int(8) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
  `username` varchar(50) NOT NULL COMMENT '用户名',
  `password` varchar(50) NOT NULL COMMENT '密码',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';

实体类

package com.battcn.entity;

/**
 * @author Levin
 * @since 2018/5/7 0007
 */
public class User {

    private Long id;
    private String username;
    private String password;
    // TODO  省略get set
}

restful 风格接口

package com.battcn.controller;

import com.battcn.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Levin
 * @since 2018/4/23 0023
 */
@RestController
@RequestMapping("/users")
public class SpringJdbcController {

    private final JdbcTemplate jdbcTemplate;

    @Autowired
    public SpringJdbcController(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @GetMapping
    public List<User> queryUsers() {
        // 查询所有用户
        String sql = "select * from t_user";
        return jdbcTemplate.query(sql, new Object[]{}, new BeanPropertyRowMapper<>(User.class));
    }

    @GetMapping("/{id}")
    public User getUser(@PathVariable Long id) {
        // 根据主键ID查询
        String sql = "select * from t_user where id = ?";
        return jdbcTemplate.queryForObject(sql, new Object[]{id}, new BeanPropertyRowMapper<>(User.class));
    }

    @DeleteMapping("/{id}")
    public int delUser(@PathVariable Long id) {
        // 根据主键ID删除用户信息
        String sql = "DELETE FROM t_user WHERE id = ?";
        return jdbcTemplate.update(sql, id);
    }

    @PostMapping
    public int addUser(@RequestBody User user) {
        // 添加用户
        String sql = "insert into t_user(username, password) values(?, ?)";
        return jdbcTemplate.update(sql, user.getUsername(), user.getPassword());
    }


    @PutMapping("/{id}")
    public int editUser(@PathVariable Long id, @RequestBody User user) {
        // 根据主键ID修改用户信息
        String sql = "UPDATE t_user SET username = ? ,password = ? WHERE id = ?";
        return jdbcTemplate.update(sql, user.getUsername(), user.getPassword(), id);
    }
}

测试

由于上面的接口是 restful 风格的接口,添加和修改无法通过浏览器完成,所以需要我们自己编写junit或者使用postman之类的工具。

创建单元测试Chapter4ApplicationTests,通过TestRestTemplate模拟GET、POST、PUT、DELETE等请求操作

package com.battcn;

import com.battcn.entity.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @author Levin
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Chapter4Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class Chapter4ApplicationTests {

    private static final Logger log = LoggerFactory.getLogger(Chapter4ApplicationTests.class);
    @Autowired
    private TestRestTemplate template;
    @LocalServerPort
    private int port;

    @Test
    public void test1() throws Exception {
        template.postForEntity("http://localhost:" + port + "/users", new User("user1", "pass1"), Integer.class);
        log.info("[添加用户成功]\n");
        // TODO 如果是返回的集合,要用 exchange 而不是 getForEntity ,后者需要自己强转类型
        ResponseEntity<List<User>> response2 = template.exchange("http://localhost:" + port + "/users", HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
        });
        final List<User> body = response2.getBody();
        log.info("[查询所有] - [{}]\n", body);
        Long userId = body.get(0).getId();
        ResponseEntity<User> response3 = template.getForEntity("http://localhost:" + port + "/users/{id}", User.class, userId);
        log.info("[主键查询] - [{}]\n", response3.getBody());
        template.put("http://localhost:" + port + "/users/{id}", new User("user11", "pass11"), userId);
        log.info("[修改用户成功]\n");
        template.delete("http://localhost:" + port + "/users/{id}", userId);
        log.info("[删除用户成功]");
    }
}

总结

本章介绍了JdbcTemplate常用的几种操作,详细请参考JdbcTemplate API文档

目前很多大佬都写过关于 SpringBoot 的教程了,如有雷同,请多多包涵,本教程基于最新的 spring-boot-starter-parent:2.0.1.RELEASE编写,包括新版本的特性都会一起介绍…

说点什么

全文代码:https://github.com/battcn/spring-boot2-learning/tree/master/chapter4

666. 彩蛋



如果你对 Dubbo 感兴趣,欢迎加入我的知识星球一起交流。


知识星球

目前在知识星球(https://t.zsxq.com/2VbiaEu)更新了如下 Dubbo 源码解析如下:

01. 调试环境搭建
02. 项目结构一览
03. 配置 Configuration
04. 核心流程一览

05. 拓展机制 SPI

06. 线程池

07. 服务暴露 Export

08. 服务引用 Refer

09. 注册中心 Registry

10. 动态编译 Compile

11. 动态代理 Proxy

12. 服务调用 Invoke

13. 调用特性 

14. 过滤器 Filter

15. NIO 服务器

16. P2P 服务器

17. HTTP 服务器

18. 序列化 Serialization

19. 集群容错 Cluster

20. 优雅停机

21. 日志适配

22. 状态检查

23. 监控中心 Monitor

24. 管理中心 Admin

25. 运维命令 QOS

26. 链路追踪 Tracing

...
一共 60 篇++

源码不易↓↓↓↓↓

点赞支持老艿艿↓↓

Python+ArcGIS实战:5步搞定土壤类型预测(附随机森林模型配置技巧) 本文详细介绍了如何结合Python与ArcGIS,利用随机森林模型进行土壤类型预测。通过5个核心步骤——数据预处理、样本创建、模型构建、空间预测与精度验证,构建了一套自动化、高精度的空间预测工作流,并提供了关键的模型配置与调参技巧,助力GIS开发者高效完成土壤制图任务。 阅读详情

相关推荐

本地服务器搭建Uptime Kuma网站监控服务

本文主要介绍如何在Linux系统中一键部署Uptime Kuma运维监控服务,并将这个服务映射至公网实现随时随地远程访问。如果您像我一样在服务器上托管了多个网站,并且没有足够的时间来手动检查每个网站的在线状态,那么当出现问题时,您可能无法及时收到通知来处理这些问题。因此,搭建一个在线监控服务是很有必要的,它可以在状态异常时提醒您,以便您能够及时处理问题,确保网站的稳定性和可用性。监控服务有很多,我最终选择了Uptime Kuma,因为Uptime Kuma是开源免费的,

Tiam_cr的博客 1826

SpringBoot2.0数据访问(一)JDBCTemplate

本文作者:朱英龙意见反馈:15065421873@163.com文章来源:https://blog.csdn.net/gozhuyinglong版权声明:本文版权归作者所有,转载请注明出处 一、运行环境IDE:IDEA 2018.1.1Tomcat:8.5数据库:MySQL测试工具:Postman一、创建一个SpringBoot项目1.使用IDEA创建项目Spring Boot版本:2.0.2选中...

人生就是一个不断学习的过程 1万+

避坑指南:从聚宽迁移到QMT必须知道的5个细节(含Redis连接异常处理)

本文详细解析了从聚宽迁移到QMT平台时需注意的5个关键细节,特别是Redis连接池优化和xtquant重连机制。通过实战代码示例,帮助量化团队解决信号传递稳定性、时间同步、滑点控制等核心问题,确保交易策略平稳过渡。

weixin_27303545的博客 431

spring boot整合使用jdbcTemplate

1)pom文件引入 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>...

weixin_33892359的博客 174

Oracle恢复学习实战小结

     学习oracle10g 043课程有段时间了,前一两个星期学习了backup/restore相关的内容,刚好公司有要求要为host服务器做一个备用机以防止数据意外丢失。于是,实战开始了。     首先介绍host服务器架构。host以oracle数据库作为底层数据存储,以公司总部开发的Santorin作为应用,主要提供给测试台架数据存储、数据访问、数据导入导出、用户权限管理和数据自动备份

kseawolfk的专栏 1036

【Windows】 解决联想为主的所有自带摄像头(integrate camera)打不开的毛病(特别点名小新、thinkbook、thinkpad、y7000...)

解决联想系列电脑打不开自带摄像头的问题

Iamruzi的csdn博客 3万+

springboot使用JdbcTemplate完成对数据库的增删改查

上一篇对springboot有一个简单的介绍以及使用一个简单的例子熟悉了一下springboot写法的简单流程。这一篇介绍springboot使用JdbcTemplate完成对数据库的增删改查。   首先新建一个简单的数据表,通过操作这个数据表来进行演示   DROP TABLE IF EXISTS `items`; CREATE TABLE `items` ( `id` int(1...

Java知音 1万+

Abel逆变换及其求解方法

Abel逆变换常应用在轴对称的、光学薄的火焰、羽流或等离子体重建。

weixin_49783507的博客 8384

SpringBoot2.X基础教程:SpringBoot整合JdbcTemplate【附源码】

SpringBoot2.X基础教程:SpringBoot整合JdbcTemplate【附源码】

java程序鱼的博客 2439

【雕爷学编程】Arduino智能家居之DS18B20温度传感器

1、温度和湿度控制:通过连接温度传感器和湿度传感器,Arduino可以实时监测室内环境的温度和湿度,并通过控制空调、加热器或加湿器等执行器,实现室内温湿度的自动调节。设计用户友好的界面和操作方式,提供简单直观的控制和反馈机制,以及考虑用户习惯和需求,能够提升系统的整体用户体验。这意味着用户可以根据自己的需求和创意,自定义和定制智能家居系统的功能和外观。5、能源管理:Arduino可以与电能监测模块和智能插座等设备结合使用,实时监测家庭能源的使用情况,并通过自动控制电器设备的开关,实现能源的有效管理和节约。

雕爷学编程 2878

fatal: unable to access ‘https://github.com/xxx.git/‘ OpenSSL SSL_connect: SSL_ERROR_SYSCALL 解决方案

 本文主要介绍了fatal: unable to access ‘https://github.com/xxx.git/’: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443解决方案,希望能对使用git的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 24万+

Spring Boot 2.x基础教程:使用JdbcTemplate访问MySQL数据库

在第2章节中,我们介绍了如何通过Spring Boot来实现HTTP接口,以及围绕HTTP接口相关的单元测试、文档生成等实用技能。但是,这些内容还不足以帮助我们构建一个动态应用的服务端程序。不论我们是要做App、小程序、还是传统的Web站点,对于用户的信息、相关业务的内容,通常都需要对其进行存储,而不是像第2章节中那样,把用户信息存储在内存中(重启就丢了!)。 对于信息的存储,现在已经有非常非常多...

程序猿DD 6753

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringBoot2.x入门教程:引入jdbc模块与JdbcTemplate简单使用

点击上方蓝字 ↑↑ Throwable文摘关注公众号设置星标,不定时推送高质量原创文章关注前提这篇文章是《SpringBoot2.x入门》专辑的「第7篇」文章,使用的SpringBoot...

Throwable 3751

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

一起来学SpringBoot | 第五篇:使用JdbcTemplate访问数据库

SpringBoot是为了简化Spring应用的创建、运行、调试、部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖就可以轻易的搭建出一个 WEB 工程 Spring Framework对数据库的操作在JDBC上面做了深层次的封装,通过依赖注入功能,可以将DataSource注册到JdbcTemplate之中,...

LuisChen的博客 6437

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

SpringBoot中使用JdbcTemplate访问Oracle数据库

Oracle相信大家都不陌生吧,一个大型的数据库,至于数据库,我相信各位都比较熟悉了,一个软件系统,不论是我们常做的App、小程序、还是传统的web站点,我们都有用户的信息,相关业务的数据,通常都会存储在相关数据库中,比如:MySQL,Oracle,SQL server 等等。

好看的皮囊千篇一律,有趣的灵魂万里挑一。 2780

spring boot(三) 之 使用JdbcTemplate访问MySQL数据库

spring boot(三) 之 使用JdbcTemplate访问MySQL数据库 使用JdbcTemplate之前的准备 为了能使用JdbcTemplate,添加JDBC starter 依赖。 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifact

子时不睡的博客 1万+

SpringBoot 学习——使用 JdbcTemplate 访问数据库

参考博客: [1] Spring Boot干货系列:(八)数据存储篇-SQL关系型数据库之JdbcTemplate的使用 [2] 一起来学 SpringBoot 2.x | 第五篇:使用 JdbcTemplate 访问数据库 添加依赖 &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt...

Ni_liqiang的博客 258

jdbctemplate 执行多条sql_SpringBoot2.x教程——整合使用JdbcTemplate

我在上一章节中,重点讲解了Spring中关于DataSource的一些理论知识点,接下来本章节我主要是带大家学习JdbcTemplate的使用。一. JdbcTemplate1. JdbcTemplate简介JDBC虽然能够满足大部分用户最基本的需求,但是在使用JDBC时,必须自己来管理数据库的资源,如获取PreparedStatement,设置SQL语句参数,关闭连接等操作,使用起来非常的麻烦。...

weixin_39899776的博客 922

Springboot2.x——使用JdbcTemplate简单操作数据库

springboot使用JdbcTemplate简单操作数据库,还有一些MyBatis、Hibernate、Spring Data JPA其他框架后续再研究 一、安装mysql,准备测试数据 本地安装mysql,新建数据库wx_springboot,新建表:wx_User DROP TABLE IF EXISTS `wx_User`; CREATE TABLE `wx_User` ( ...

tellmewsm 821

springboot2.x中使用hikariCP连接池

在springboot2.x,默认采用的是hikari连接池,相比druid,hikari具有更高的性能。 springboot2.x中如何使用hikari连接池 1、pom.xml中配置 <!-- jdbc starter引入 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starte...

jasnet_u的博客 1298

SpringBoot2.x系列教程——整合使用JdbcTemplate

我在上一章节中,重点讲解了Spring中关于DataSource的一些理论知识点,接下来本章节我主要是带大家学习JdbcTemplate的使用。 一. JdbcTemplate 1. JdbcTemplate简介 JDBC虽然能够满足大部分用户最基本的需求,但是在使用JDBC时,必须自己来管理数据库的资源,如获取PreparedStatement,设置SQL语句参数,关闭连接等操作,使用起来...

qianfeng_dashuju的博客 532

SpringBoot2.X + JDBCTemPlate批量插入数据代码总结

JDBCTemPlate从接触JAVA开始就会用到这个工具,它是原生JDBC的更高一级别的工具性质的操作类,对原生JDBC进行了很多细节上的封装,只提供了入口API,使用者只需要选对API然后传对应的参数即可;将原有的比较繁琐的细节实现屏蔽了,对于使用的角度来说,表现得更加的友好;这次在这里对JDBCTemPlate的实现细节与API底层不做阐述,这是记录它对于批量数据插入的使用方法,方便后期回顾的时候能够快速上手;话不多少,直接上代码: 1. 项目工程是Maven整合SpringBoot2.x进行开发的

weixin_42745915的博客 1823

【SpringBoot总结】3. SpringBoot整合JdbcTemplate

一、JdbcTemplate是什么 它是Spring框架自带的对JDBC操作的封装,使用spring的注入功能,可以把DataSource注册到JdbcTemplate之中,目的是提供统一的模板方法使对数据库的操作更加方便、友好。SpringBoot2.x中在原来spring-jdbc基础上进行了又一次封装,位于spring-boot-starter-jdbc,该模板的权限定命名是:org.spr...

小确幸的博客 1998

springboot 引入jdbc驱动_SpringBoot2.x入门教程:引入jdbc模块与JdbcTemplate简单使用

这是公众号《Throwable文摘》发布的第23篇原创文章,收录于专辑《SpringBoot2.x入门》。前提这篇文章是《SpringBoot2.x入门》专辑的第7篇文章,使用的SpringBoot版本为2.3.1.RELEASE,JDK版本为1.8。这篇文章会简单介绍jdbc模块也就是spring-boot-starter-jdbc组件的引入、数据源的配置以及JdbcTemplate的简单使用。...

weixin_39624389的博客 567
上一篇: 数据库中间件 Sharding-JDBC 源码分析 —— SQL 解析(三)之查询SQL
下一篇: 数据库中间件 Sharding-JDBC 源码分析 —— SQL 解析(四)之插入SQL
公众号-芋道源码
博客等级 码龄10年 1639粉丝 377原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值