【Spring框架】

手写Spring框架 在学习完Spring框架之后, 我们知道了 Spring容器, IOC, AOP, 事务管理, SpringMVC 这些Spring的核心内容, 也知道了它们底层实现的基本原理, 比如Spring容器就是个Map映射, IOC底层就是反射机制, AOP底层是动态代理, SpringMVC不就是对Servlet进行了下封装嘛! 哈哈, 当然这些只是些皮毛, Spring除此之外还有更加复杂的设计, ... 阅读详情

 

一、spring

* 轻量级框架

* 负责管理对象的生命周期

* spring是一个容器

 

二、spring框架的搭建

* 引入spring的jar ,还需要引入一个公共的commons-logging.jar

   

* 建议在src根目录下创建一个applicationContext.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"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

" >http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">



    <!-- 通过bean标签进行配置,声明哪些类对象交给spring管理 -->

    <bean id="userService" class="com.service.UserService"></bean>

</beans>

* 将引入spring-beans.xsd 增加具体的版本号spring-beans-4.1.xsd

* 默认情况下会根据uri从网络中寻找指定的xsd文件。

* 会寻找到所有版本的xsd,默认使用最高版本。

* 所以建议指定版本。

* 在java中,加载spring框架,并创建spring容器。

* 获得一个spring的BeanFactory对象或者其扩展的子类ApplicationContext对象

BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml") ;

* 从容器中获得指定的bean对象。

UserService service = (UserService) factory.getBean("userService");

 

三、spring的核心

* IOC  Inversion of Control 控制反转

* 以前所有的service(dao,domain)对象在需要使用的时候由我们编程人员通过代码主动创建

* 使用spring之后,将主动权交给spring容器

* 我们在使用时可以通过beanFactory获得或者通过DI实现注入。

* 被动的获得所需要的对象。

* AOP Aspect Oriented Programming 是一种编程模式(思想)

 

四、DI Dependency injection 依赖注入

* 依赖注入是IOC的一种体现

* 实现方式

* 构造器注入

* 在bean标签中使用<constructor-arg> 指定构造器参数的值。

* 根据标签的位置对应构造器中的参数

* 使用constructor-arg的value属性为参数赋予具体的值。

* 使用constructor-arg的ref属性将spring管理的另一个bean对象作为参数赋值。

 <bean id="user" class="com.domain.User">

    <constructor-arg value="1002"></constructor-arg>

    <constructor-arg value="dmc"></constructor-arg>

    <constructor-arg value="123"></constructor-arg>

</bean>

* set方法注入

* 在bean标签中使用<property>子标签为指定的属性赋值

* 通过property的name属性指定为哪个属性赋值,要求与属性名对应(本质是与set方法名对应)

* 通过property的value属性为指定的属性赋予具体的值。

* 通过property的ref属性将spring管理的另一个bean对象作为参数赋值。

 <bean id="user2" class="com.domain.User">

    <property name="uno" value="1003"></property>

    <property name="uname" value="world"></property>

    <property name="upass" value="321"></property>

</bean>

 

* 自动注入

* 自动注入不能赋予简单的值,只能是将spring管理的bean对象作为参数赋值

* 在bean标签通过autowire属性设置开启自动注入

* 基于构造器注入的自动注入,只支持按照类型注入!

<bean id="a" class="com.domain.A"></bean>

<bean id="b" class="com.domain.B"></bean>

<bean id="user" class="com.domain.User" autowire="constructor"></bean>

public User(A a, B b) {

this.a = a;

this.b = b;

}

* 如果有多个构造器可以使用,会默认使用参数匹配最多那个构造器

* 如果有两个子类实现了同一个接口,在自动注入时两个子类都可以使用时,默认谁都不用。

    

* set方法注入支持byType和byName    

* byName 只根据name匹配(set方法名匹配)

 <bean id="a" class="com.domain.A"></bean>

 <bean id="user2" class="com.domain.User" autowire="byName"></bean>

  -----------------------------------------------------

  class User{

private A a ;

private A aa ;

  }

  ----------------------------------------------------

  a : com.domain.A@324324324

  aa : null

* byType 会根据类型匹配,不考虑名字

 a : com.domain.A@324324324

 aa : com.domain.A@324324324

 * 如果找到了2个bean对象符合同一个参数类型,此时抛出异常:

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException:

No qualifying bean of type [com.domain.C] is defined: expected single matching bean but found 2: c1,c2

 

五、bean对象的作用域

* 在bean标签中使用scope属性设置bean对象的作用域。

* 默认情况下spring创建的bean对象是单实例。

* singleton 单实例(默认)

* prototype 多实例

* 一般在开发中都建议(struts2)action是多实例的, service和dao一般都建议是单实例的。

 

六、bean对象的延迟加载

* 通过懒加载可以设置bean对象是在第一次使用时创建还是在加载spring框架时创建。

* 默认是关闭懒加载,启动时就创建。

* 开启懒加载:

* 在bean标签中使用lazy-init=true设置懒加载

* 在beans根标签中设置

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"

    default-lazy-init="true"    

>

* 如果bean对象是多实例的,一定是注入时再创建。不受懒加载影响。

 

七、声明式事务

* 需要提供一个公共数据源(连接池)

* dbcp

* c3p0

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">

    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>

    <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>

    <property name="username" value="dmc"></property>

    <property name="password" value="456"></property>



    <property name="minIdle" value="2"></property>

    <property name="maxIdle" value="10"></property>

    <property name="maxTotal" value="100"></property>

    <property name="maxWaitMillis" value="2000"></property>

</bean>

 

 

* 需要定义一个事务管理者 (切面)

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

    <property name="dataSource" ref="dataSource"></property>

</bean>

* 需要定义事务管理者的管理策略 (通知)

<tx:advice id="txAdivce" transaction-manager="txManager">

<tx:attributes>

<tx:method name="save*" isolation="SERIALIZABLE" propagation="REQUIRED" rollback-for="java.lang.Throwable" />

<tx:method name="update*" isolation="SERIALIZABLE" propagation="REQUIRED" rollback-for="java.lang.Throwable" />

<tx:method name="delete*" isolation="SERIALIZABLE" propagation="REQUIRED" rollback-for="java.lang.Throwable" />

<tx:method name="find*" read-only="true" />

</tx:attributes>

</tx:advice>

* 什么时间点使用该策略(切入点)

<aop:config>

<aop:advisor advice-ref="txAdivce" pointcut="execution(* com.service.*.*(..))"  />

</aop:config>

 

** 扩展:

* 将数据源的连接信息定义在properties文件中,将其引入到spring的配置文件里

* 在spring的配置文件里使用类似于el的语法${driver}引用properties中的内容。

* 参考doc/5.8.2 Customizing configuration metadata with a BeanFactoryPostProcessor

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

    <property name="locations" value="classpath:db-config.properties"/>

</bean>

 

db-config.properties

driver=oracle.jdbc.driver.OracleDriver

url=jdbc:oracle:thin:@localhost:1521:orcl

username=dmc

password=456

 

ApplicationContext.xml

 

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">

<property name="driverClassName" value="${driver}"></property>

<property name="url" value="${url}"></property>

<property name="username" value="${username}"></property>

<property name="password" value="${password}"></property>

 

<property name="minIdle" value="2"></property>

<property name="maxIdle" value="10"></property>

<property name="maxTotal" value="100"></property>

<property name="maxWaitMillis" value="2000"></property>

</bean>

 

八、Spring整合Mybatis

* spring整合mybaits主要是spring框架负责管理mybatis的SqlSessionFactory

* spring框架负责管理mybatis与数据库交互的事务处理

(1)引入jar包

 spring3.x与mybatis的整合需要引入一个额外的jar包,提供sm的整合

(2)整合时要求数据源必须交给spring管理。

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
	<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
	<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
	<property name="username" value="dmc"></property>
	<property name="password" value="456"></property>
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<property name="configLocation" value="classpath:configuration.xml"></property>
</bean>


configuration.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<mappers>
		<mapper resource="com/dao/CarMapper.xml"/>
	</mappers>
</configuration>

(3) 声明式事务

spring和mybatis整合时,使用的就是springjdbc自带的事务管理者, 如果要使用事务管理者提供的session对象,需要继承SqlSessionDaoSupport父类。该类提供了一个getSession()方法,来获得事务管理者管理的session对象。此时不建议service继承Support类,所以最好还是提供一个dao类。 Support父类需要一个SqlSessionFactory,记得注入。

 

【Spring框架】Spring概述及基本应用 Spring框架优点,构建及demo 阅读详情

相关推荐

Spring框架

Spring框架 一、初始Spring 1、Spring概述 Spring官网:https://spring.io/ Spring目前已经形成了一个开发生态圈,不是一个单一的项目,Spring提供了若干个项目(全家桶),每个项目完成特定的功能。 2、Spring Framework系统架构 Spring Framework是Spring生态圈中最基础的项目,是其他项目的根基。 Spring Framework是一个轻量级的JavaEE企业级开发框架。Spring Framework的核心是依赖注入(

sinat_35450260的博客 2568

Spring原理讲解

Spring原理讲解

d_drj123的博客 201

从‘包饺子’到‘包络线’:一个生活化比喻讲透长期与短期成本决策

本文通过饺子馆经营的生活化比喻,深入浅出地解析了长期与短期成本决策的核心逻辑。从调整人力(可变成本)到扩建厨房(固定成本),揭示了包络线理论在商业决策中的实际应用,帮助企业主在规模经济与成本控制间找到平衡点。

weixin_32006655的博客 342

spring简介

1、spring简介 Spring是一个分层的 full-stack(一站式)轻量级框架,以Ioc(Inversion of Control,控制反转)和AOP(Aspect Oriented Programming,面向切片编程)为内核,使用简单的JavaBean来完成以前只能由EJB(Enterprise Java Beans)完成的工作,取代了臃肿、低效的EJB。Spring致力于JavaEE应用各层的解决方案,是企业应用一站式开发很好的选择,在表现层它提供了Spring MVC以及整合Struts的

清风微凉亦暖心 747

Vivado固化程序与Flash型号添加实战指南

本文详细介绍了Vivado程序固化到Flash芯片的完整流程,包括基础操作、Flash型号添加方法及疑难问题排查。针对Vivado官方支持列表缺失的Flash型号,提供了手动添加配置的详细步骤和参数说明,并分享了高级技巧与安全操作建议,帮助开发者高效完成FPGA程序固化。

weixin_29291573的博客 567

手把手教你编写PCIe设备驱动:基于Linux内核的实战教程

本文详细介绍了基于Linux内核的PCIe设备驱动开发全流程,包括环境准备、设备探测、中断处理、DMA配置等核心内容。通过实战代码示例和Makefile编写指南,帮助开发者快速掌握PCIe驱动开发技术,实现高性能设备驱动开发与优化。

weixin_30687051的博客 194

大家所说的full-stack框架到底是指什么?

轻量级框架:整合层guiceORM层nutz, guzz表示层            -- None --            JSF            Spring MVC            Struts 2            Tapestry 5            Web Services Only            JSF            Spring MVC(-...

weixin_34334744的博客 382

帆软FineBI考试题

Flint 补录表,有批次删除功能。在分析主题内添加数据时能够选择批量添加数据。插件安装过程中有报错提示需要下载 Fine I for Excel 运行环境进行修复,修复完毕后重新安装插件。图例显示支持自定义设置,且图例标题支持隐藏显示。finebi中的指标如果想进行维度区间/真的自定义分组,不能直接拖拽到组建区域中需要先转化为维度方可进行指标分组。excel报表不支持分页。

Davina_yu的博客 1609

Spring知识点小结(一)

一、Spring的简介 1、spring是一个full-stack轻量级开源框架 2、spring的两大核心 IoC: inverse of control 控制反转:反转是对象的创建权,由原来自己new方式变成让spring容器(IoC容器)创建对象 作用:完成解耦合 AOP: 面向切面编程(底层实现:动态代理) 作用:不修改源码的情况下,对...

weixin_33860147的博客 180

SPSS线性混合模型实战:手把手复现一篇老年认知研究的统计结果(含代码)

本文详细介绍了如何使用SPSS线性混合效应模型复现老年认知研究的统计结果,涵盖数据准备、模型构建、结果解读及可视化全流程。特别针对重复测量数据分析,提供了SPSS菜单操作与语法编写的实用技巧,帮助研究者高效处理复杂数据并验证模型假设。

weixin_42562079的博客 518

SAP物料主数据中的销售视图。这是一个在销售与分销模块中至关重要的核心主数据,直接关系到从报价到交货的整个销售流程

SAP物料主数据的销售视图是销售流程的核心基础,它定义了物料如何被销售、定价、开票和交付。销售视图包含五个关键控制点:1)基本销售数据控制物料销售状态;2)销售组织数据决定销售渠道和产品分类;3)通用物料数据管理销售描述和税务分类;4)交货计划控制交付参数;5)开票计划管理定价规则。这些设置直接影响销售流程顺畅度、数据准确性、客户满意度、财务合规性和业务灵活性。建议将销售视图创建纳入新产品引入流程,并建立规范的维护机制,确保业务变化时及时更新配置。

金牌架构师 667

spring框架概述

1 spring框架概述 1.1 什么是spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson开发。 它是为了解决企业应用开发的复杂性而创建的。框架的主要优势之一就是其分层架构,分层架构允许使用者选择使用哪一个组件,同时为 J2EE 应用程序开发提供集成的框架 dao(JdbcTemplate...

weixin_30622107的博客 365

YOLO26涨点改进| TGRS 2026 | 独家创新首发、注意力改进篇| 引入CSSCA频谱-空间交叉注意力,含多种创新改进,小目标检测、图像分割、高光谱图像分类、语义分割任务任务涨点

🔥本文提出CSSCA(频谱-空间交叉注意力)模块,通过中心像素引导的光谱与空间交叉注意力机制,有效提升YOLO26模型的特征表达能力。该模块实现了光谱与空间信息的协同优化,能够自适应强化关键通道与重要空间区域,增强模型对小目标和复杂场景的感知能力。文章详细介绍了CSSCA的网络结构、工作原理及四大优势,包括精准特征表达、协同信息优化、小样本适应性和轻量化设计。同时提供了完整的代码实现和四种改进方案的YAML配置文件,包括基础版、增强版、C3k2融合版和C2PSA融合版,为YOLO26模型的性能提升

Ai缝合怪、助力小伙伴高效发论文 269

什么是spring框架?spring框架到底有什么用?spring框架到底做了些什么?

什么是spring框架,spring框架究竟有什么用呢?我们可以用spring框架来做些什么呢?让我们来具体了解一下,以及经常所说的IOC和AOP是一种怎样的思想,到底是怎么实现这些思想的!

小汤圆的博客 3万+

Python-自动化绘制股票价格通道线

创建更强大、更可靠的价格通道检测算法。

探索人工智能领域 949

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

【Spring框架】Spring框架介绍

文章目录Spring框架介绍Spring两大核心技术Spring的优点Spring体系介绍核心容器数据访问/集成Web页面其他模块 Spring框架介绍 Spring框架是分层的 Java SE/EE 应用 full-stack 全栈式轻量级开源框架,以 IOC(Inverse Of Control:控制反转)和 AOP(Aspect Oriented Programming:面向切面编程)为内核,提供了展现层 SpringMVC 和持久层 Spring JDBC 以及业务层事务管理等众多的企业级应用技术

Super_Powerbank的博客 1661

深度学习工具包 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框架介绍_Spring框架介绍

spring框架介绍 这是Spring框架和Spring核心概念的简介。 在本教程中,我们将介绍Spring Framework的主要优点和功能。 在随后的教程中,我们将学习有关Spring和Spring Boot的更多信息。 总览 我们知道, Spring框架是Java开发人员中最受欢迎的应用程序框架。 Spring以为Java 几乎可以完成的所有工作提供抽象和基础结构框架而闻名。 在较...

最佳 Java 编程 1309

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

重学Spring框架系列之——什么是Spring框架

说在前面 Spring框架算得上是java程序员必备的一项技能了。不论是早期的SSM或SSH架构,还是现在流行的SpringBoot加SpringCloud构建的分布式、微服务架构。Spring在其中扮演着不可或缺的角色,其重要性也是不言而喻的。 为了更好的工作和自身的提升,菜鸟又重新学习了一下Spring框架,在学习的过程中也有一些收获,从而想着通过文章将自己的学习过程记录下来。也希望可以帮助到有需要的人。如果文章中存在不合理或错误的地方也希望大家可以提出来,我会及时改正,希望我们可以一起进步。 既然我们

first_M的博客 590

spring框架_Spring框架介绍

spring框架 这是Spring框架和Spring核心概念的简介。 在本教程中,我们将介绍Spring Framework的主要优点和功能。 在随后的教程中,我们将学习有关Spring和Spring Boot的更多信息。 总览 我们知道, Spring Framework是Java开发人员中最受欢迎的应用程序框架。 Spring以为Java几乎可以完成的所有工作提供抽象和基础结构框架而闻名。 ...

cunhui1209的博客 206

如何下载Spring框架

首先进入Spring官网:https://spring.io/ 点击PROJECTS   找到SPRING FRAMEWORK 并点击  因为是托管在github上的,所以点击github标志  找到Spring Framework Artifacts 找到Spring仓库连接  点击Artifacts选项 然后找到菜单下的 libs-release-local...

liutao2001的博客 2万+

【Spring】(1)Spring概述:什么是Spring框架?为什么要用Spring框架?

两个月前跟着b站动力节点王鹤老师的Spring框架教程视频学习完了Spring框架,在学习过程中我将视频中涉及的代码都一行一行手敲了一遍,并且把Spring入门相关的资料整理了一下,在这里记录一下我在Spring框架学习过程中的笔记和一些心得,希望能帮助到想要通过文字教程入门Spring这一框架的小伙伴哦! 视频地址:2020最新Spring框架教程【IDEA版】-Spring框架从入门到精通 文章目录第一部分 Spring概述1. 什么是 Spring 框架2. Spring 的优点1)轻量2)面向接.

aaa_hao的博客 6252
上一篇: 【Elastic Search学习总结】17.ES Java API --复杂查询
下一篇: 【SpringMVC简要总结】1. SpringMVC简介(3.x)
Rita楠神
博客等级 码龄9年 27粉丝 61原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值