Mybatis和Spring、SpringMVC的整合

spring mvc高级篇(一):Spring+SpringMVC+Hibernate整合 1.1整合思路分析 Java Web应用开发经过多年的发展,已经形成了一套成熟的程序结构。一个典型的使用了SpringMVC和Hibernate框架的应用,其结构如下图所示。 SpringMVC+Hibernate应用的程序结构        SpringMVC的主控制器DispatcherServlet接到请求后会调用特定的Controller。在Controller中又会调 阅读详情

1.创建一个maven工程

导入jar包,pom.xml的配置如下:

<dependencies>
<dependency>
	<groupId>junit</groupId>
	<artifactId>junit</artifactId>
	<version>4.12</version>
	<scope>test</scope>
</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>5.0.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>5.0.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>5.0.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>5.0.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
			<version>5.0.6.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.2</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.25</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.taglibs</groupId>
			<artifactId>taglibs-standard-spec</artifactId>
			<version>1.2.5</version>
			<type>bundle</type>
		</dependency>
		<dependency>
			<groupId>org.apache.taglibs</groupId>
			<artifactId>taglibs-standard-impl</artifactId>
			<version>1.2.5</version>
			<type>bundle</type>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.46</version>
		</dependency>
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc6</artifactId>
			<version>12.1.0.1-atlassian-hosted</version>
		</dependency>
		<dependency>
			<groupId>com.mchange</groupId>
			<artifactId>c3p0</artifactId>
			<version>0.9.5.2</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.4.6</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.3.2</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis.generator</groupId>
			<artifactId>mybatis-generator-core</artifactId>
			<version>1.3.7</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis.caches</groupId>
			<artifactId>mybatis-ehcache</artifactId>
			<version>1.1.0</version>
		</dependency>
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper</artifactId>
			<version>5.1.4</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<extensions>true</extensions>
			</plugin>
		</plugins>
	</build>

2.在web.xml里做spring和springmvc的初始配置

3.SpringMVC只扫描Controller和ControllerAdvice

<!-- 配置包扫描 -->
    <context:component-scan base-package="com.hy.springmvc" use-default-filters="false">
        <context:include-filter type="annotation" 			
expression="org.springframework.stereotype.Controller"/>
        <context:include-filter type="annotation" 
expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>
<context:component-scan base-package="cn.ybzy.ssmweb" use-default-filters="false">
	<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	<property name="prefix" value="/WEB-INF/jsp/"></property>
	<property name="suffix" value=".jsp"></property>
</bean>
<mvc:annotation-driven></mvc:annotation-driven>
<mvc:default-servlet-handler/>

4.Spring排除扫描Controller和ControllerAdvice

<!-- 配置包扫描 -->
    <context:component-scan base-package="com.hy.springmvc">
        <context:exclude-filter type="annotation" 			
expression="org.springframework.stereotype.Controller"/>
        <context:exclude-filter type="annotation" 
expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>

5.jdbc.properties配置

jdbc.user=root
jdbc.password=root
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/mybatisdemo

orcl.user=scott
orcl.password=scott
orcl.driverClass=oracle.jdbc.OracleDriver
orcl.jdbcUrl=jdbc:oracle:thin:@localhost:1521:orcl

jdbc.acquireIncrement=10
jdbc.initialPoolSize=30
jdbc.minPoolSize=5
jdbc.maxPoolSize=40
jdbc.maxStatements=1000
jdbc.maxStatementsPerConnection=100

6.Spring的配置

<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置C3P0数据连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
	<property name="user" value="${jdbc.user}"></property>
	<property name="password" value="${jdbc.password}"></property>
	<property name="driverClass" value="${jdbc.driverClass}"></property>
	<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
	<property name="acquireIncrement" value="${jdbc.acquireIncrement}"></property>
	<property name="initialPoolSize" value="${jdbc.initialPoolSize}"></property>
	<property name="minPoolSize" value="${jdbc.minPoolSize}"></property>
	<property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
	<property name="maxStatements" value="${jdbc.maxStatements}"></property>
	<property name="maxStatementsPerConnection" value="${jdbc.maxStatementsPerConnection}"></property>
</bean>
<!-- 事务配置 -->
<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置事务属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
	<tx:attributes>
		<tx:method name="get*" read-only="true"/>
  <tx:method name="load*" read-only="true"/>
		<tx:method name="find*" read-only="true"/>
		<tx:method name="select*" read-only="true"/>
		<tx:method name="*" read-only="false"/>
	</tx:attributes>
</tx:advice>
<!-- 配置事务的切入点 -->
<aop:config>
	<aop:pointcut expression="execution(* cn.ybzy.springdemo.service.*.*(..))" 
			id="txPointcut"/>
	<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
<!-- 整合Mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<property name="configLocation" value="classpath:mybatis-config.xml"></property>
		<property name="mapperLocations" value="classpath:cn/ybzy/ssmweb/dao/*.xml"></property>
</bean>

<mybatis-spring:scan base-package="cn.ybzy.ssmweb.dao"/>

7.log4j.properties

log4j.rootLogger = debug,stdout, D
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.Threshold = INFO
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p %m%n
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = ./log4j.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern=%d %p %m%n
5.Spring+Mybatis+SpringMVC整合 前端时间搭建了一个关于新闻的后台,使用Restful风格,向前台提供json格式数据。 对于刚学习的时候会觉得整合三个框架是一件很难的事情,但是当自己都熟悉了之后再来整理下思路其实也没有那么难。 就是把三个模块整合运行起来,然后写上自己的业务逻辑就形成了一个项目。 今天把就思路整一下,加深自己的印象,首先谈一下这三个东西分别是什么。 spring  Spring是一个开源框架,Sprin 阅读详情

相关推荐

SpringMVC Spring Mybatis整合步骤

一.配置mybatis   1.在pom.xml中导入mybatis3.4.5的依赖,导入mysql-connector-java-5.1.43      2.写mybatis-config-xml的配置文件,里面包含连接数据库的信息和映射文件   3.实体类和对应的映射文件(person,person.xml)   4.dao接口   5.写一个测试类测试mybatis是否可以使用

qq_40158032的博客 2829

【Java】spring+springmvc+hibernate最完整整合配置教程

【Java】spring+springmvc+hibernate最完整整合配置教程。SpringMVC只扫描Controller和ControllerAdvice。Spring排除扫描Controller和ControllerAdvice。

只恨天高的博客 1879

MAVEN整合Spring+SpringMVC+Mybatis

2016/1/20 14:47:28原创,转载请注明出处曾经看过《那些年我们一起追过的女孩》,片中有个比较经典的画面,至今记忆犹新,柯景腾多年后,做了一名作家,每天面对电脑码字,背后是一张张一闪而过的字幅“人生就是不停的战斗”作为程序员,我想一生就是不停的和BUG做战斗了,新来的这家公司,用的很老的Spring+Struts2.0+JDBC的框架,非常的不好用,其中的问题可以陈述10条以上,但是限于

kang82651204的博客 8063

spring+springmvc+hibernate整合

我看了下很多楼主的博客,写的东西毕竟不是很适合自己所想要的;我这里边通透的讲解及说下 我先说由配置再到代码(我把hibernate的配置和spring的配置整合在一起的 尽量做到零配置 我把相关的配置都放在src/config包下的 你看下配置的代码 你应该就看出来啦) 第一个便是web.项目里配置   spring-mvc                  cont

rainjm的博客 887

SpringMVC、Mybatis与Spring整合实战演示

本文还有配套的精品资源,点击获取 简介:SpringMVC、Mybatis和Spring是Java开发中常用的三大框架,它们分别负责不同层次的应用开发。Spring作为基础容器负责对象管理和依赖注入;SpringMVC处理Web层的请求分发;Mybatis专注于数据访问层,简化了SQL操作。整合这三大框架能够构建出高效的模块化企业级应用。本文通过SSMDemo项目实例,详细...

weixin_29097457的博客 1095

Spring、MyBatis与SpringMVC整合的实践教程

在现代Web应用开发中,为了提高开发效率和降低维护成本,越来越多的开发者选择整合Spring、MyBatis和SpringMVC这三个强大的框架。Spring提供了全面的企业级服务支持,MyBatis作为数据持久层框架,实现了对象关系映射(ORM),而SpringMVC则专注于Web层的MVC模型处理。整合这三者能够构建出一个结构清晰、功能完善的Java应用,易于扩展和维护。Spring框架是一个全面的企业级应用开发框架,它为Java开发人员提供了一整套解决方案。

weixin_34618526的博客 1057

【SSM整合】SpringMVC + Spring + Mybatis整合详细教程

本文为SpringMVC + Spring + Mybatis整合教程相关详细介绍,从数据库数据准备、相关依赖包添加、创建项目基本结构和配置框架,到Mybatis层的编写、Spring层的编写、SpringMVC层的编写,再到前端页面编写等,最后进行运行与测试,按步骤对SSM框架整合进行详细的解析~

小新要变强的博客 5429

SpringMVC+Hibernate+Spring整合实例

SpringMVC+Hibernate+Spring整合实例源码下载,很完整的例子,需要的可以下载源码学习

Spring、SpringMVC、Mybatis 整合

Spring、SpringMVC、Mybatis 整合 文章目录Spring、SpringMVC、Mybatis 整合1、Pom.xml配置1.1 Maven依赖的导入1.2 静态资源导出配置2、Spring和Mybatis整合2.1 创建applicationContext.xml2.2 创建mybatis-config.xml2.3 创建database.properties2.4 创建spring-dao.xml3 SpringMVC层3.1 配置web.xml3.2 创建spring-mvc.xml

xiaoxiao66668的博客 1467

基于SpringMVC+Spring+Hibernate的JAVA WEB敏捷开发系统.zip

基于SpringMVC+Spring+Hibernate的JAVA WEB敏捷开发系统

从FreeCAD到BIMBase:PlaneGCS约束求解器的移植使用指南

本文为BIMBase平台的开发者提供了一份详细的PlaneGCS几何约束求解器移植与集成指南。文章深入探讨了如何从FreeCAD中提取PlaneGCS核心代码,并将其适配到BIMBase的C++二次开发环境中,重点解决了内存管理、数据模型桥接、约束抽象以及性能调优等关键问题,旨在帮助开发者构建稳定高效的参数化设计模块。

weixin_29213525的博客 321

SpringMVC快速入门第四讲——Spring、MyBatis和SpringMVC的整合

之前我整合了Spring和MyBatis这两个框架,不会的可以看我的文章MyBatis框架的学习(六)——MyBatis整合Spring。本文我再来讲SpringMVC和MyBatis整合开发的方法,这样的话,Spring、MyBatis和SpringMVC三大框架的整合开发我们就学会了。这里我使用的Spring是Spring4.1.3这个版本(SpringMVC自然也是这个版本),MyBatis是

李阿昀的博客 9332

数字化转型是什么?核心又是什么呢?

01到底什么是数字化转型? 这时候你或许要问笔者了,既然你说使用新兴技术不是数字化转型,那使用新的商业模式总该是数字化转型了吧?你比如阿里巴巴,作为我们中国人最熟悉的开展电子商务的公司,它可以说是新的商业模式最大的开创者了:阿里巴巴是世界上最大的零售商,却没有任何一家实体店和任何库存;再比如优步(Uber),我们非常熟悉的一个线上打车平台,它可以算是世界上最大的出租车公司了,但是它不拥有一辆出租车。还有近些年来,我们经常使用的的旅游房屋租赁社区爱彼迎(Airbnb),它可以为消费者提供多样的住宿信息..

weixin_58342023的博客 4043

Spring Springmvc Mybatis整合流程

Spring Springmvc Mybatis整合流程 导入jar包 1.导入相应的jar包 <!--spring相关的jar包--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version...

qq_45857788的博客 320

echarts如何实现3D饼图(环形图)?

自定义修改3D饼图的宽高和legend

i-cat的博客 1万+

ESP32C6+ESP-IDF5.2实战:基于RS485的ModbusRTU从站开发与调试

本文详细介绍了基于ESP32C6和ESP-IDF5.2开发ModbusRTU从站的实战指南。涵盖硬件连接、协议实现、ESP-Modbus库移植、寄存器映射及调试技巧,帮助开发者快速构建稳定可靠的工业级RS485通信节点,并解决常见通信故障。

play7的博客 1189

Spring__SpringMVC__Mybatis整合

Springmvc是controller层的,mybatis是dao和mapper层的,而spring类似粘合剂,springmvc与mybatis之间是不能直接整合的,而是通过springmvc和spring之间,mybatis与spring之间整合的。 ##Spring容器和SpringMVC容器的关系 Spring容器是一个父容器,SpringMVC容器是一个子容器,它继承自Spring容器...

qq_37432174的博客 457

STorM BGC V1.31硬件+SimpleBGC固件:从零搭建三轴云台开发环境(Keil+JLink避坑指南)

本文详细介绍了如何从零搭建STorM BGC V1.31硬件+SimpleBGC固件的三轴云台开发环境,涵盖硬件连接、Keil+JLink开发工具配置、固件编译与烧录等关键步骤,并提供了常见问题的解决方案和调试技巧,帮助开发者快速上手三轴云台开发。

weixin_28693683的博客 381

Spring整合SpringMVC及Mybatis

文章目录1、环境的搭建整合说明:整合的思路创建数据库和表结构创建maven的工程(今天会使用到工程的聚合和拆分的概念,这个技术maven高级会讲)2、搭建Spring框架3、搭建SpringMVC框架4、Spring整合SpringMVC框架5、搭建MyBatis框架6、Spring整合MyBatis框架 1、环境的搭建 整合说明: SSM整合可以使用多种方式,咱们会选择XML + 注解的方式 使用Spring去整合Mybatis和SpringMVC 整合的思路 先搭建整合的环境 先把Spring的

weixin_44051048的博客 365

ESP32天线阵列实现Wi-Fi空间成像与无直视定位

Wi-Fi信道状态信息(CSI)是OFDM系统中表征多径传播特性的基础物理层参数,其复数值包含幅度与相位,可反映无线环境的空间特征。基于CSI的射频感知技术,通过提取子载波级信道响应,结合阵列信号处理,实现到达角(AoA)估计与深度映射,本质是将通信链路重构为空间域传感器。该技术无需专用雷达硬件,具备低成本、被动式、隐私友好等工程优势,在室内定位、行为识别、仓储导航等场景具有广泛落地价值。本文聚焦ESP32平台,详解多芯片相位同步、CSI零拷贝采集、嵌入式MUSIC算法及信道图谱轻量化部署等关键实现。

weixin_30632267的博客 237

YOLO26优化:注意力魔改 | 用于微小目标检测的上下文增强和特征细化网络ContextAggregation,助力小目标检测,暴力涨点

用于微小目标检测的上下文增强和特征细化网络ContextAggregation,助力小目标检测

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

Spring整合SpringMVC和Mybatis框架

搞定算法,面试字节再不怕,有需要文章中分享的这些二叉树、链表、字符串、栈和队列等等各大面试高频知识点及解析最后再分享一份终极手撕架构的大礼包(学习笔记):分布式+微服务+开源框架+性能优化《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!外链图片转存中…(img-tJgoNF5L-1713426181509)][外链图片转存中…(img-sBdecCO2-1713426181509)]

2401_83703866的博客 1022

华为eNSP镜像包全集下载,包含CE6800、CE12800、NE系列等!

你好,这里是网络技术联盟站。昨天给大家介绍了win11、10下安装eNSP最新系列(1.3.00)并完美运行,附下载。从文章发布到发文前,一直有朋友想让瑞哥提供一下华为ENSP镜像包,今天安排!eNSP安装包、以及eNSP中所需要的镜像包(设备包)(CE、CX、NE40E、NE5000E、NE9000、USG)例如:导入一个USG设备包,eNSP中的USG5500和USG6000V都是可以启动的。如果你的报错“40”的话,那么打开Oracle VM VirtualBox这个虚拟机,删除对应报错的虚拟机,然后

网络技术联盟站 3万+

SpringMVC,Spring和Mybatis的整合

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一、pandas是什么? 二、使用步骤 1.引入库 2.读入数据 总结 前言 提示:这里可以添加本文要记录的大概内容: 例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。 提示:以下是本篇文章正文内容,下面案例可供参考 一、pandas是什么? 示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数..

shenxianba的博客 237

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

MyBatis-Spring-SpringMVC 整合

MyBatis-Spring-SpringMVC 整合 文章目录MyBatis-Spring-SpringMVC 整合1、整个 MyBatis 和 Spring:所有的 jar 包导入2、引入 MyBatis 之前的配置:mybatis-config.xml3、SpringMVC 配置文件的编写:spring-servlet.xml4、Spring 配置文件的编写:applicationContext.xml 1、整个 MyBatis 和 Spring:所有的 jar 包导入 Spring 核心包(IOC)

前尘忆梦的博客 725

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

SpringMVC+Spring+Mybatis整合步骤

SpringMVC+Spring+Mybatis整合步骤 1、SpringMVC SpringMVC是spring框架的一个模块,Spring和SpringMVC无需通过中间曾进行整合。 SpringMVC是基于mvc的WEB层框架。 MVC:Model View Controller 缩写 1.1、SpringMVC 运行原理 执行过程: a)当用户发起Http请求,以字符串的形式发送: ...

qq_45122010的博客 826

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

上一篇: Mybatis调用存储过程
下一篇: 【Java】Mybatis工作流程和插件开发
synchronizeOn
博客等级 码龄3年 1193粉丝 64原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值