spring02_ioc使用注解对mysql数据库进行增删改查

Spring-SpringBoot-SpringMVC三大框架的学习 三大框架 阅读详情

基于上一讲XML配置改造使用注解:

 

bean.xml里面的内容:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.hr"></context:component-scan>

<!--    配置QueryRunner-->
    <bean id="runner" class="org.apache.commons.dbutils.QueryRunner" scope="prototype">
<!--        注入数据源-->
        <constructor-arg name="ds" ref="dataSource"></constructor-arg>
    </bean>

<!--    配置数据源-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/eesy"></property>
        <property name="user" value="root"></property>
        <property name="password" value="123456"></property>
    </bean>

</beans>

改造1: 项目代码:   https://github.com/2402zmybie/spring02_account_ioc_anno
至此,改造完毕, 下一讲, 直接去掉配置文件bean.xml. 纯注解实现配置类, 笔记:

/**
 * 该类是一个配置类, 它的作用和bean.xml是一样的
 *  Configuration: 指定当前类是一个配置类
 *  ComponentScan:
 *      作用:用于通过注解指定spring在创造容器时要扫描的包
 *      属性:
 *          value:它和basePackages的作用是一样的,都是用于指定创建容器时要扫描的包
 *          <context:component-scan base-package="com.hr"></context:component-scan>
 *  Bean:
 *      作用: 用于把当前方法的返回值作为bean对象存入spring的ioc容器中
 *      属性:
 *          name: 用于指定bean的id, 当不写时, 默认值是当前方法的名称
 *      细节:
 *          当我们使用注解配置方式时,如果方法有参数,spring框架会去容器中查找有没有可用的bean对象,查找的方式和Autowired注解的作用一样
 *  Import:
 *      作用: 用于导入其他的配置类
 *      属性:
 *          vaule:用于指定其他配置类的字节码, 使用Import的注解之后, 有Import注解的类就是父配置类,而导入的都是子配置类
 *  PropertySource:
 *      作用: 用于properties文件的位置
 *      属性:
 *          value: 指定文件的名称和路径
 *               关键字: classpath: 表示类路径下
 */
@Configuration
@ComponentScan(value = {"com.hr"})
@Import({JdbcConfig.class})
@PropertySource("classpath:jdbcConfig.properties")
public class SpringConfiguration {


}

项目地址:   https://github.com/2402zmybie/spring02_account_annoioc_withoutxml

从零开始构建Maven+Spring+MyBatis+MySQL增删改查项目 Apache Maven是一个强大的项目管理和构建自动化工具。其主要目的是让开发者能够理解项目的构建过程,并且为项目提供一个通用的构建生命周期框架。Maven不仅简化了项目管理,还提供了一致的方法来构建项目,生成文档,报告和构建项目,与项目内部和外部的依赖关系。Maven项目通常包含一个名为pom.xml的项目对象模型文件,这个文件包含了项目的配置信息,包括项目构建的路径,项目的依赖关系以及构建的步骤。为了开始使用Maven,你需要按照约定的目录结构创建项目文件夹,并在该文件夹中创建。 阅读详情

相关推荐

MyBatis 基于注解的增删改查示例(Spring IOC注入)

MyBatis 基于注解的增删改查示例程序,使用Spring的IOC机制注入,降低程序间的耦合性

Spring-IOC的账户增删改查(完全用注解)

创建配置类SpringConfiguration @ComponentScan("com.itheima") @Import(JdbcConfig.class)//用于导入其他的配置类 @PropertySource("classpath:jdbcConfig.properties")//用于指定properties文件的位置 public class SpringConfiguration { } 其他配置类JdbcConfig public class JdbcConfig { @Val

weixin_43633568的博客 266

Spring通过注解实现IOC

Spring通过注解实现IOC,Spring通过注解实现IOC,Spring通过注解实现IOC

使用注解和IOC优化增删改查步骤

一、优化配置文件 1.原先的配置文件里面不仅有全局的配置,而且数据库的用户名和密码都写死在代码里,有容易暴露和难以修改的缺点,所以下面加了一个配置文件进行优化; 2.原先对象的创建都是在配置文件里实现,如果创建一万个对象将要在配置文件bean一万个对象,过程特别繁杂,所以引入注解的方式,简化代码 以下是增加的配置文件: 容易修改且不影响内部代码的运行 二、使用注解...

weixin_30532759的博客 216

spring boot maven 连接mysql实现增删改查

myeclipse创建maven工程使用spring boot连接Mysql实现增删改查

MyBatis 基于Mapper的增删改查示例(Spring IOC注入)

MyBatis 基于Mapper的增删改查示例程序,使用Spring的IOC机制注入,大大降低程序间的耦合性

Spring day02 注解配置,增删改查,整合junit

细节:当我们使用注解配置方法时,诶过方法有参数,spring框架会去容器中查找有没有可用的bean对象,查找的方式和Autowired注解的作用是一样的。另外,集合类型的注入只能通过XML来实现。* 当我们使用Import的注解之后,有Import注解的类就是主配置(父配置类),而导入的都是子配置类。* 他们的作用就和在xml配置文件中的bean标签中写一个(property)标签的作用是一样的。

Anyway_01的博客 983

PX4二次开发实战:从零构建自定义飞控模块

本文详细介绍了PX4二次开发的实战指南,从环境搭建到自定义飞控模块的创建,涵盖了uORB消息定义、外部传感器驱动集成、控制算法实现等关键步骤。通过具体代码示例和调试技巧,帮助开发者快速入门PX4二次开发,构建高效稳定的无人机飞控系统。

weixin_29175469的博客 339

Spring--03基于注解的IoC配置实现账户的CRUD

项目说明 此项目采用纯注解配置的方式完成IoC配置 此项目使用mysql作为数据库 使用dbutils作为数据封装工具类 使用c3p0作为数据源 整合了spring和junit 实现对账户的添加,查找,更新,删除。 注意 使用注解配置IoC时,bean.xml需要更换不同的约束。 搭建开发环境 数据库表account 新建maven工程,编写pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave

Ur_Eyes_的博客 216

声音事件检测metric:PSDS

这项工作为多声道声音事件检测(SED)系统的性能评估定义了一个新的框架,它克服了传统的collar-based事件决定、事件F-cores和事件错误率的限制。拟议的框架引入了对事件检测的定义,该定义对标签的主观性更为稳健。它还采用了多声道接收器操作特性(ROC)曲线,以提供比F1分数更全面的系统性能洞察力,并建议将这些曲线简化为单一的多声道声音检测分数(PSDS),这允许系统独立于操作点(OPs)进行比较。所提出的方法还能更好地了解不同声音类别的数据偏差和分类稳定性。

Maestro_T的博客 2727

机器学习——径向基函数(RBF)神经网络

目录 一、什么是基函数 二、什么是径向基函数 三、为什么RBF神经网络使用一个径向基函数作为隐含层的激活函数 四、参数训练 五、RBF网络vs BP网络和 SVM 一、什么是基函数 著名的傅里叶变换是指:n个有参(权值)的正、余弦三角函数基的和式可以等价的表示任意一个周期函数,这里的“基”和我们数学中说的坐标基或向量基含义相同,即坐标空间中任意一个向量都可以用基向量的线性和表示出来。 因此,我们引入函数空间的概念,函数空间中的每个连续函数可以表示为基函数的线性组合,就像向量空间中的每..

CHWB2580的博客 6271

day02 spring-ioc

spring之ioc

Libra_97的博客 479

【数据集处理】中国地面气候资料日值数据集(V3.0)(含MATLAB全代码)

简介数据集数据处理

WW、forever的博客 1万+

Spring IoC/DI

Bean对象的实例化方式,Spring属性注入的方法,Bean的生命周期,注解在Spring上的使用

2401_88007700的博客 2236

YOLOv8优化:独家创新(SC_C_Detect)检测头结构创新,实现涨点 | 检测头新颖创新系列

独家创新(SC_C_Detect)检测头结构创新,适合科研创新度十足,强烈推荐

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 4865

Python之achatbot包语法、参数和实际应用案例

本书是一本PyTorch深度学习实战指南,分为基础(前6章)和进阶(后5章)两大部分。基础部分涵盖张量运算、神经网络、数据预处理及CNN等核心内容;进阶部分则深入图像、文本、音频建模技术,重点解析Transformer架构及大语言模型开发。全书采用"理论+实践"模式,适合从零基础到进阶的PyTorch学习者。

王国平的博客 631

[spring]MyBatis介绍 及 用MyBatis注解操作简单数据库

简单来说 MyBatis 是更简单完成程序和数据库交互的框架,也就是更简单的操作和读取数据库⼯具--需要修改到上述mapper接口所对应的路径-->> < mapper namespace = " com.bite.mybatis.mapper.UserInfoXmlMapper " > >

m0_73992740的博客 1212

基于LED可见光通信的物联网系统设计_344

随着物联网技术的不断发展,传统无线通信在工业环境中面临电磁干扰强、通信质量不稳定等问题。为此,本文设计了一种基于LED可见光通信的物联网系统,实现工厂车间内设备状态的稳定、高效、低干扰数据传输。系统主要由设备节点、设备主机、华为云物联网服务器以及可视化上位机构成。 设备节点采集机器的出货量、运行状态、机身温度等关键信息,通过调制后的LED可见光信号发送至设备主机。主机利用红外接收器接收光信号后进行解调处理,并通过WIFI模块将数据上传至华为云IOT服务器。

343

Spring基于XML&&Mysql | 注解&&Mysql的简单IOC案例

奥德赛

qq_40181435的博客 580

基于ESM3微调的抗菌肽生成器:技术方案与实现

基于ESM3微调的抗菌肽生成器:技术方案与实现 摘要 本文提出了一种基于ESM3蛋白质语言模型的抗菌肽生成框架,采用两阶段训练策略:先在151万肽序列上预训练,再在1.3万抗菌肽数据上微调。模型能够生成具有合理长度分布、低重复率且高新颖性的抗菌肽序列。文章详细介绍了数据预处理流程、模型架构设计、训练策略及评估方法,为抗菌肽的理性设计提供了有效的计算工具。实验结果表明,该方法生成的抗菌肽序列在保持生物活性的同时具有较高的结构多样性。 关键词:抗菌肽设计;蛋白质语言模型;ESM3;深度学习;序列生成

huanghm88的专栏 175

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

spring+c3p0连接池+dbutils+mysql+junit测试基于注解实现ioc编程

标题spring+c3p0连接池+dbutils+mysql+junit测试基于注解实现ioc编程 (1)导入spring,c3p0,dbutilsr,junit,dbutils的依赖坐标到pom.xml,导入后idea会自动从网上下载相关jar包。 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.

BUG粉碎机 293

深度学习工具包 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")

使用spring的IoC的实现账户的CRUD

使用spring的IoC的实现账户的CRUD 需求 实现账户的CRUD操作 技术要求 使用spring的IoC实现对象的管理 使用DBUtils作为持久层解决方案(后续会使用JdbcTemplate,和Mybatis) 使用c3p0数据源 目标: 使用Spring去整合第三方的框架DBUtils,并完成开发 使用XML配置IOC 使用D...

少营营的博客 217

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Spring Boot 常用注解

Spring Boot 常用注解,注解是Spring Boot的“魔法标签”,用对了能让你的代码又快又优雅!

奔跑的坏蜗牛 854

注解IOC案例-把自己编写的类使用注解配置

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="htt...

Leon_Jinhai_Sun的博客 157

Spring注解驱动开发第34讲——你了解基于注解版的声明式事务吗?

不知不觉,时间已快过一个月了,而这个Spring注解驱动开发系列教程才写到第34讲,实在是说不过去,我向大家宣布一件事情,那就是: 我是一个傻逼! 我是一个傻逼! 我是一个傻逼! 我得承认这样一个事实,但无论如何抱怨,路还是要继续走下去,这可真是一件没有道理的事情。 好吧!回到正文,在这一讲中,我来向大家讲解一下声明式事务,也就是看看Spring用注解是如何来简化对数据库事务的开发的。 搭建声明式事务的环境 是个人都知道,在对数据库进行增删改操作时,必然是要使用到事务的。因此,接下来,我们就来搭建好声明

李阿昀的博客 2738

spring整合dbutils+c3p0实现数据的增删改查

前面两篇文章和大家分享了spring的IOC和DI工作原理。今天我们利用spring+dbutils+mysql来做一个简单的demo。这个demo的功能主要是银行账户的一些信息,实现基本的增删查改操作。 采用XML形式实现demo 采用XML和注解形式实现demo 采用注解形式实现demo 首先,我们创建一个maven工程,搭建spring的开发环境。 项目结构如下: 读者暂且不用管con...

qq_32403043的博客 796
上一篇: spring02_ioc依赖注入之使用注解
下一篇: Spring03-动态代理
zmybiealex
博客等级 码龄10年 48粉丝 46原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值