框架(一)Spring4入门

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

1.spring_AOP的开发入门

1.创建web项目,引入jar包
在这里插入图片描述
2.引入spring配置文件
=====引入aop的约束

<beans
	    xmlns="http://www.springframework.org/schema/beans"
   	    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd"> 

3.编写目标类并完成配置
创建dao和dao的实现

public interface ProductDao {
	public void save();
	
	public void delete();
	
	public void update();
	
	public void find();
}
public class ProductDaoImpl implements ProductDao {

	@Override
	public void save() {
		System.out.println("保存.....");
	}

	@Override
	public void delete() {
		System.out.println("删除.....");
	}

	@Override
	public void update() {
		System.out.println("更新.....");
	}

	@Override
	public void find() {
		System.out.println("查询......");
	}

}

完成xml的配置

 <!-- 配置目标对象        目标类-->
    <bean id="productDao" class="spring_aop2.ProductDaoImpl"/>

4.编写一个测试类
spring整合Junit测试类:引入一个jar包即可

spring-test-4.2.4.RELEASE

编写测试类

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")//加载配置文件
public class Spring_aop_test {
	@Resource(name="productDao")//注入xml中的id
	private ProductDao productDao;
	public void demo(){
		productDao.save();//调用ProductDaoImpl方法实现
		productDao.delete();
		productDao.find();
		productDao.update();
	}
}

5.增强某个方法,编写一个切面类MyAspectXML.java

/**
 * @author Leonard
 *	切面类
 */
public class MyAspectXML {
	public void check(){
		System.out.println("权限校验==============");
	}
}

6.将切面类交给spring去管理

 <!-- 将切面类交由spring管理 -->
    <bean id="myAspectJ" class="spring_aop2.MyAspectXML" />

7.通过AOP配置实现方法增强

<!-- 通过AOP对目标类产生代理 -->
    <aop:config>
        <!-- expression表达式 -->
        <aop:pointcut expression="execution(* spring_aop2.ProductDaoImpl.save(..))" id="daoId"/>
        <!-- 配置切面 -->
        <aop:aspect ref="myAspectJ">
            <aop:before method="check" pointcut-ref="daoId"/>
        </aop:aspect>
    </aop:config>

8.SpringAop的切入点表达式写法
语法:

【访问修饰符】 方法返回值 包名.类名.方法名(参数);

例:

public void com.leonard.customerDao.save(..);

2.Spring的AOP基于AspectJ的注解开发

1.引入必要的jar包
2.编写配置文件ApplicationContext.xml

<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"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd">

3.编写目标类OrderDao.java实现增删改查

public class OrderDao {
	public void save(){
		System.out.println("保存订单.....");
	}
	public void delete(){
		System.out.println("删除订单......");
	}
	public void update(){
		System.out.println("更新订单......");
	}
	public void find(){
		System.out.println("查找订单......");
	}
}

4.配置目标类。xml

<!--     配置目标类 -->
<bean id="order" class="spring.demo1.OrderDao">  </bean>

5.编写切面类并配置

/**
 * @author Leonard
 *注解的切面类
 */
public class MyAspectAnno {
	public void before(){
		System.out.println("前置注解增强.......");
	}
}

<!-- 配置切面类 -->
    <bean id="myAspect" class="spring.demo1.MyAspectAnno"></bean>

6.使用注解的AOP对目标类进行增强
步骤如下:
-------6.1在配置文件中打开注解的AOP开发

<!--  配置文件中开启Aop注解开发 -->
    <aop:aspectj-autoproxy />

=====6.2在切面类上使用注解

@Aspect
public class MyAspectAnno {
	//代表OrderDao里的save方法使用前置增强
	@Before(value = "execution(* spring.demo1.OrderDao.save(..))")
	public void before(){
		System.out.println("前置注解增强.......");
	}
}

7.编写Spring测试类

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class SpringDemo {
	@Resource(name="order")
	private OrderDao orderDao;
	@Test
	public void demo(){
		orderDao.update();
		orderDao.save();
		orderDao.find();
		orderDao.delete();
	}
}

控制台输出

更新订单......
前置注解增强.......
保存订单.....
查找订单......
删除订单......

注:后置增强只需要MyAspectAnno切面类加入注解即可,其他代码保持不变

@AfterReturning("execution(* spring.demo1.OrderDao.delete(..))")
	public void afterReturnning(){
		System.out.println("后置增强.....");
	}

3.Spring的JDBC模板使用

3.1入门————普通方法
1.引入jar包
在这里插入图片描述
2.创建数据库,建表
在这里插入图片描述
3.创建一个简单的JDBC模板


public class demo1_jdbc {
	@Test
	public void demo1(){
		//1.创建连接池
		DriverManagerDataSource datasource = new DriverManagerDataSource();
		//2.连接数据库
		datasource.setDriverClassName("com.mysql.jdbc.Driver");
		datasource.setUrl("jdbc:mysql:///spring_1");
		datasource.setUsername("root");
		datasource.setPassword("123456");
		//3.创建jdbc模板
		JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
		jdbcTemplate.update("insert into account values(null,?,?)", "abc",1000000d);
	}
}

4.结果
在这里插入图片描述
3.2JDBC模板使用升级-------交给spring管理【使用默认连接池-----不常用】
引入jar包,如上
1.配置spring的xml文件

<!--      1. 配置spring内置连接池 -->
<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <!-- 属性注入 -->
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql:///spring_1"></property>
        <property name="username" value="root"></property>
        <property name="password" value="123456"></property>
      </bean>      
       <!--  2.配置Spring的JDBC模板     -->
       <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="datasource"></property>
       </bean>
</beans>

2.创建JDBC【注解方式】

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class spring_2 {
	@Resource(name="jdbcTemplate")
	private JdbcTemplate jdbctemplate;
	
	@Test
	public void demo(){
		jdbctemplate.update("insert into account values(null,?,?)", "bbb",222222d);
	}
}

3.结果
在这里插入图片描述
3.3JDBC模板使用升级-------交给spring管理【配置使用DBCP连接池----了解】
1.额外引入jar包
在这里插入图片描述
2.xml配置文件

      <!-- 2.dbcp配置连接池 -->
      <bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql:///spring_1"/>
            <property name="username" value="root"/>
            <property name="password" value="123456"/>
      </bean>
       <!--  2.配置Spring的JDBC模板     -->
       <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="datasource"></property>
       </bean>

3.创建测试类,操作数据库

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class spring_2 {
	@Resource(name="jdbcTemplate")
	private JdbcTemplate jdbctemplate;
	
	@Test
	public void demo(){
		jdbctemplate.update("insert into account values(null,?,?)", "ccc",333333d);
	}
}

结果
在这里插入图片描述

3.3JDBC模板使用升级-------交给spring管理【配置使用c3p0连接池----重点】
1.引入c3p0需要的jar
在这里插入图片描述
2.在xml文件中配置c3p0连接池

 <!-- c3p0配置连接池 -->
      <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="com.mysql.jdbc.Driver"/>
            <property name="jdbcUrl" value="jdbc:mysql:///spring_1"/>
            <property name="user" value="root"/>
            <property name="password" value="123456"/>
      </bean>
       <!--  2.配置Spring的JDBC模板     -->
       <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="datasource"></property>
       </bean>

3.创建测试类,操作数据库

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class spring_2 {
	@Resource(name="jdbcTemplate")
	private JdbcTemplate jdbctemplate;
	
	@Test
	public void demo(){
		jdbctemplate.update("insert into account values(null,?,?)", "ddd",555555d);
	}
}

4.结果
在这里插入图片描述
3.4JDBC模板使用升级-------交给spring管理【提取再升级完成】
抽取配置到属性文件
1.定义属性文件:jdbc.properties

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///spring_1
jdbc.username=root
jdbc.password=123456

2.在Spring配置文件引入属性配置文件

 <!-- 引入配置文件 -->
      <context:property-placeholder location="classpath:jdbc.properties"/>
 <!-- 引入相应的值 -->
      <bean id="datasoource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="${jdbc.driverClass}"/>
            <property name="jdbcUrl" value="${jdbc.url}"/>
            <property name="user" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
      </bean>

3.创建测试类,写入数据库

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class spring_2 {
	@Resource(name="jdbcTemplate")
	private JdbcTemplate jdbctemplate;
	
	@Test
	public void demo(){
		jdbctemplate.update("insert into account values(null,?,?)", "eee",555555d);
	}
}

结果
在这里插入图片描述

一文学会Spring,Spring最简单的入门教程(万字好文) spring教程 阅读详情

相关推荐

JeeSite4开源框架入门篇(一)

摘要:今天无意中发现一个较好的开源框架JesSite,JeeSite4是一个 Java EE 企业级快速开发平台,基于经典技术组合(Spring Boot、Spring MVC、Apache Shiro、MyBatis、Beetl、Bootstrap、AdminLTE)在线代码生成工具,通过自己的研究算是基本入门,以下是笔记。 JeeSite4.0的文档比较全面,按照文档给出的步骤,即可搭建出项...

待你归来的博客 9633

Spring 4——快速入门

什么是Spring: Spring是分层的JavaSE/EE full-stack(一站式) 轻量级开源框架 分层: SUN提供的EE的三层结构:web层、业务层、数据访问层(持久层,集成层) Spring框架有对三层的每层解决方案: web层:Spring MVC. 持久层:JDBC Template. 业务层:Spring的Bean管理。 Spring的核心: IOC:(Inverse of ...

weixin_45492425的博客 243

Spring快速入门

引言 最近几天一直在忙着学习数据结构和算法,关于JavaEE的框架也有一阵子没更新了。那么今天就来聊一聊Spring框架吧,针对该框架写一篇快速入门的文章。 Spring简介 Spring框架是由于软件开发的复杂性而创建的。Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途不仅仅限于服务器端的开发。从简单性、可测试性和松耦合性角度而言,绝大部分J...

。。。 1万+

Spring入门,看这篇就够了

一篇对Spring入门案例演示的文章,仅供正在学习Spring的小伙伴们参考哟!

m0_54928777的博客 3870

Spring框架快速入门实战案例

在现代的Java应用开发中,Spring框架已经成为了一个不可或缺的组成部分。自2003年首次发布以来,Spring一直以其简化企业级开发的强大能力而闻名,使得开发者能够轻松创建可测试、可维护且易于管理的代码。本章将介绍Spring框架的基本概念、发展历史以及它在现代Java应用开发中的重要性。通过阅读本章,读者将对Spring有一个初步的了解,并认识到学习Spring的必要性。依赖注入(Dependency Injection, DI)是一种设计模式,它允许创建对象的组件与查找其依赖项的过程解耦。

weixin_42522857的博客 1051

别再手动算考勤了!教你用Python+企业微信API自动生成月度报表

本文介绍如何利用Python和企业微信API构建自动化考勤分析系统,实现从数据获取到可视化报表生成的全流程自动化。通过企业微信打卡接口获取数据,使用Pandas进行高效清洗和分析,并生成Excel和HTML格式的报表,大幅提升考勤统计效率。系统支持智能判定考勤状态,如迟到、早退等,并可通过定时任务实现月度自动化运行。

weixin_27875131的博客 290

Spring入门基础

我们通常所说的 Spring 指的是 Spring Framework(Spring 框架),它是⼀个开源框架,有着活跃⽽庞 ⼤的社区,这就是它之所以能⻓久不衰的原因。Spring ⽀持⼴泛的应⽤场景,它可以让 Java 企业级的 应⽤程序开发起来更简单。而Spring的本质其实就是是包含了众多⼯具⽅法的IoC 容器。这里我们有两个关键字,一个是IoC,另一个则是容器。1.2 什么是容器容器是⽤来容纳某种物品的(基本)装置。比如我们Java中常用的List/Map就是一种数据存储容器。

weixin_60778429的博客 3374

红外回充方案之红外接收和发射/附源码(1)

本文介绍了基于NEC协议的红外回充方案实现,重点讲解了红外收发原理和GD32F330单片机的接收端实现。文章首先说明采用38kHz载波和一体化红外接收管的设计优势,能有效抗环境光干扰。接着详细解析NEC协议格式,包括9ms起始信号、地址码、命令码及其反码校验机制,并给出逻辑1和0的调制方式。在接收端实现上,展示了GD32F330定时器输入捕获配置代码,通过双边沿触发测量脉冲宽度进行解码。文章还提供了状态机设计思路和数据结构,为低成本机器人红外回充方案提供了完整的技术实现方案。

m0_59406757的博客 1241

Spring快速入门超详细讲解

在Spring框架规范中,所有由spring管理的对象都称之为Bean对象。Spring提供了以下多个注解,这些注解可以直接标注在java类上,将它们定义成Spring Bean。注解说明@Component该注解用于描述Spring中的Bean,它是一个泛化的概念,仅仅标识容器中的一 个组件(Bean),并且可以作用在任何层次,例如Service层、Dao层等,使用时只需将该注解标注在相应的类上即可。

南 阳 的博客 5088

TK抓包协议分析:So层逆向

第三个参数是一个回调函数,这里他的返回值1表示成功,0表示失败,那我们手动把他Hook为0,让他不支持quic协议,实现降级。等,我们是为了解决抓包问题,那很有可能是在net目录下(network),那来搜索一下。开了抓包以后APP直接是网络无连接了,并且抓到的请求也是不正常的,下面我们就开始定位。看了半天感觉也没啥有用的东西,那下面我们整理一下已经有信息,来猜测一下,后续怎么进行。那可以猜测,我们真正需要Hook的那个函数也有可能是这样加载的,可以字符串搜索一下。

2503_90751938的博客 3421

手把手教你用STM32F303和LAN9252搭建EtherCAT从站(附IO/AD/DA完整代码)

本文详细介绍了如何使用STM32F303和LAN9252搭建EtherCAT从站,涵盖硬件选型、开发环境配置、协议栈移植及IO/AD/DA功能实现。通过实战指南和完整代码,帮助开发者快速掌握工业自动化中的实时通信技术,提升系统性能与可靠性。

weixin_26802933的博客 235

Spring入门第一讲——Spring框架的快速入门

Spring的概述什么是Spring据度娘所载: Spring是一个开源框架,Spring是于2003年兴起的一个轻量级的Java开发框架,由Rod Johnson创建。简单来说,Spring是一个分层的JavaSE/EEfull-stack(一站式)轻量级开源框架。 Spring是一个开源框架,Spring是于2003年兴起的一个轻量级的Java开发框架,由Rod Johnson在其著作Exp

李阿昀的博客 14万+

VTK API 详解(115):vtkScalarBarActor - 显示颜色条

显示用于颜色映射的标量值范围。自动从vtkMapper中提取。可设置颜色条的位置、大小、字体、标签格式等。支持横向或纵向显示颜色条。是进行科学数据伪彩色可视化时非常重要的辅助工具,它能让用户直观地理解不同颜色代表的数值大小。通过灵活设置颜色表、标题、标签数量等,可以适配多种可视化需求。

yumeiguo的博客 490

Spring框架入门

​本篇文章主要从**什么是spring**、**spring入门案例**、**spring创建对象的原理**等方面进行对spring入门的学习。

LYH2771994122的博客 1148

【Proteus仿真】基于AT89C51单片机的单片机双向通信

本文介绍了基于AT89C51单片机实现双向通信的系统设计。系统采用MAX232芯片实现TTL与RS-232电平转换,通过CONN-D9F接口建立串行通信连接。甲机程序通过按键控制发送不同指令字符,同时接收乙机数据驱动数码管显示;乙机程序根据接收指令控制LED显示状态,并可发送0-10数字至甲机。文中详细说明了MAX232电平转换原理、DB9接口定义,以及完整的单片机控制程序代码,包括串口初始化、数据收发处理等关键功能实现,为嵌入式系统串口通信开发提供了实用参考方案。

XU157303764的博客 1095

iOS远程真机之WebDriverAgent 天坑记

一、WDA安装依赖报错:       这个东西神坑,我搞了一天都没找到解决方案,最后在appium讨论中发现,       解决方案是:       先定位到WebDriverAgent 所在路径$ cd /Users/XXXX/git/WebDriverAgent        然后运行:mkdir -p Resources/WebDriverAgent.bundle sh ./Scripts/b

甫式人生 7318

Java Spring框架 (底层原理+入门)

Java Spring框架 Spring 一、Spring的概述 定义: Spring框架是一个开放源代码的J2EE应用程序框架,由Rod Johnson发起,是针对bean的生命周期进行管理的轻量级容器(lightweight container)。 Spring解决了开发者在J2EE开发中遇到的许多常见的问题,提供了功能强大IOC、AOP及Web MVC等功能。 Spring可以单独应用于构筑应用程序,也可以和Struts、Webwork、Tapestry等众多Web框架组合使用,并且可以与 Swing

程序员猫爪 3万+

173、NPU的编译器开发:开源社区贡献指南

本文分享了在NPU编译器开源社区贡献的经验心得。作者通过实际案例(如卷积维度错误、NaN输出等)阐述了NPU编译器开发的特殊性:硬件迭代快、边界条件复杂、厂商代码不可全信。提出有价值的贡献应聚焦硬件适配测试、性能剖析工具和反模式文档三类内容。强调用实测数据沟通、主动承担维护责任、保持代码通用性等社区协作技巧,并建议通过RFC提前沟通、附硬件实测数据等方式提高PR通过率。最后指出,NPU编译器开发是与聪明人共同填坑的过程,鼓励开发者提交"有诚意的代码"而非完美代码。

m0_50546716的博客 38

Spring框架——入门一

1. spring概述 1.1 框架是什么(了解) 框架是一个封装了很多组件的半成品。 1.2 Spring是什么(理解) Spring是分层的 Java SE/EE应用 full-stack 轻量级开源框架,以 IoC(Inverse Of Control:反转控制)和 AOP(Aspect Oriented Programming:面向切面编程)为内核。 提供了展现层 SpringMVC和持久...

Yitouxiufa的博客 254

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

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Spring基础框架 一 入门

Spring 入门 第一天

小菜鸡的博客 980

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Spring框架入门指南

Spring是一个轻量级的Java开发框架,由Rod Johnson创建。它主要通过使用JavaBean来实现软件的解耦,简化了Java企业级应用的开发。Spring的核心是控制反转(IoC)和面向切面编程(AOP)。Spring框架是一个功能强大且灵活的开发框架,它通过控制反转和依赖注入简化了Java应用的开发。通过本文的介绍,你已经了解了Spring的基本概念,并搭建了一个简单的Spring Boot应用。希望这篇文章能帮助你更好地入门Spring开发。

Amsssssssssss的博客 1088

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Spring5总述(一)——Spring框架概述及入门案例

Spring框架总述 Spring框架概述 Spring是轻量级的开源的Java框架. Spring可以解决企业应用开发的复杂性. Spring有两个核心部分:I

mydesss的博客 4919

一、Spring的基础入门 SSM框架,对Spring框架入门讲述,傻瓜式操作的入门操作

SSM框架,对Spring框架入门讲述,傻瓜式操作的入门操作

qq_39656243的博客 1011

Spring框架:基础入门

在Java的生态系统中,Spring框架作为一个顶级的开源项目,已经成为了Java开发的标准之一。

qq_35763697的博客 1491

spring框架入门

spring框架是目前为止java最流行的框架,没有之一,它是一个轻量级的框架,它是开源的框架。内部的源码(听说)优美。所以学习spring框架是java开发比较之路。本文带领大家一起进入spring框架入门。当然spring框架不能局限于会使用它,还要研究它的源码,今后一起学共勉。 ...

新春客 1273

Spring系统学习(一)——初识Spring框架

Spring 是一个流行的基于 Java 的开源框架,旨在简化企业级应用程序的开发。最初,它是为了简化 Java 企业版(Java EE)的复杂性而设计的,经过不断发展,Spring 已经成为支持各类应用开发的全栈生态系统,包括 web 开发、数据访问、消息服务等。它的核心理念是控制反转(IoC)和依赖注入(DI),这有助于提高代码的模块化、可测试性和可维护性。

2301_79858914的博客 1356
上一篇: 数据库之Linux下Redis的学习
下一篇: 框架(二)Spring框架之使用JDBC模板实际案例
一朝游
博客等级 码龄8年 0粉丝 20原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值