整合SSM

SSM整合thymeleaf 之前学习SSM的时候前端页面还是一直用jsp搭建的,虽然jsp用着挺不爽但是确实我用了挺久的。 最近学了thymeleaf,发现网上主要的资料还是springboot整合thymeleaf的,很少用springmvc直接整合的 因此根据官网文档试着整合一下 准备工作 thymelef+spring官方文档:https://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html 一个整合了的SSM小应用,在网上随便扒拉了一个简单的整合,简单. 阅读详情

动动手啊动动脚啊清晨深呼吸

只是一个简单的整合,项目中没有子模块

  • IDEA+Spring+Spring mvc+Mybatis+MySQL+Maven

准备

什么叫整合SSM?

  • 有一种整合方式就是controller所在的mvc可以使用spring的IOC,事物可以控制mybatis的dao层

在整合SSM之前,我们需要明白:

  • 单个的spring、spring mvc、mybatis项目需要什么?
  • pom中需要新增哪些包?
  • 整合的时候配置文件做了哪些改动?

整合思路及各模块功能

spring
  • 实现IOC和事物管理的AOP
  • 通过applicationContext.xml的编写
    • 扫描注解包,不扫描controller包
    • 事物管理
spring mvc
  • 完成视图层的请求和响应
  • 通过web.xml配置过滤器来解决中文乱码,配置DispatcherServlet来加载spring-mvc.xml
  • spring-mvc.xml用来扫描controller包,配置视图解析器,过滤静态资源,自动注解等
  • spring和spring mvc整合通过web.xml配置的监听器加载applicationContext.xml来整合
  • 此时,web的三大组件:servlet,filter,listener全部具备
mybatis
  • 主要通过注解的形式来完成对数据库的操作
  • 未整合之前需要配置一个SqlMapConfig.xml来配置关于mybatis相关的数据库连接,以及扫描的xml或注解
  • spring和mybatis整合会消除SqlMapConfig.xml,把配置和applicationContext.xml放到一起

SSM整合实例

创建项目环境
  • 项目的完整目录如下

在这里插入图片描述

  • 在pom中导入jar包
<?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="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.zo10ng</groupId>
  <artifactId>ssmDemo0.1</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>ssmDemo0.1 Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <spring.version>5.0.2.RELEASE</spring.version>
  </properties>


  <dependencies>
    <!--spring-->
    <!--spring核心类-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--管理bean的类IOC-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--spring容器,提供扩展,支持IOC-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--aop-->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.6.8</version>
    </dependency>
    <!--spring aop,需要依赖core-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--事物管理-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--web引用开发用到的核心类,如监听器的ServletContext,外部依赖context和core-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--spring mvc框架使用-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--对spring dao特性进行了扩展-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--spring jdbc template-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--和Junit配合使用-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--测试-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!--servlet-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
    <!--jsp-->
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.0</version>
      <scope>provided</scope>
    </dependency>
    <!--jstl表达式解析-->
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <!--mybatis-->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.5.0</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.3.0</version>
    </dependency>
    <!--连接池-->
    <dependency>
      <groupId>com.mchange</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.5.2</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>

    <!--mysql-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.16</version>
    </dependency>

    <!--增强注解-->
    <dependency>
      <groupId>javax.annotation</groupId>
      <artifactId>jsr250-api</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>ssmDemo0.1</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
  • 在resources中的applicationContext.xml用来配置spring和mybatis
<?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"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!--开启注解扫描,不希望处理controller-->
    <context:component-scan base-package="zi10ng">
        <!--不扫描Controller的注解-->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--spring整合mybatis-->
    <!--连接池-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.cj.jdbc.Driver"/>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ssm1?useSSL=false&amp;serverTimezone=Hongkong&amp;characterEncoding=utf-8&amp;autoReconnect=true"/>
        <property name="user" value="root"/>
        <property name="password" value="root"/>
    </bean>
    <!--SQLSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--包-->
    <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="zi10ng.dao"/>
    </bean>

    <!--spring声明式事物管理-->
    <!--事物管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--事物通知-->
    <tx:advice id="txAdvice">
        <tx:attributes>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>
    <!--aop增强-->
    <aop:config>
        <aop:advisor advice-ref="txAdvice" pointcut="execution(* zi10ng.service.impl.ProductServiceImpl.*(..))"/>
    </aop:config>
</beans>
  • 同时创建spring-mvc.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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--开启注解扫描,只扫描controller-->
    <context:component-scan base-package="zi10ng.controller"/>

    <!--配置视图解析器-->
    <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--过滤静态资源-->
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/js/**" location="/js/"/>
    <mvc:resources mapping="/img/**" location="/img/"/>
    <mvc:resources mapping="/plugins/**" location="/plugins/"/>

    <!--spring mvc注解的支持-->
    <mvc:annotation-driven/>

</beans>
  • 上面两个xml文件都需要通过web.xml来加载
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>

  <!--配置监听器,加载application.xml。默认加载webapp里的application-->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>


  <!--配置过滤器,解决中文乱码-->
  <filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


  <servlet>
    <!--springMvc默认的servlet容器-->
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <!--该容器需要再次加载资源包中的xml文件去读取注解等信息-->
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>
编写service,controller和dao
  • dao
package zi10ng.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;
import zi10ng.domian.Product;

import java.util.List;

/**
 * @author Zi10ng
 * @date 2019年7月18日16:15:25
 */
public interface ProductDao {

    /**
     * 查询所有产品
     * @return list形式
     */
    @Select("select * from product")
    List<Product> findAll();

    /**
     * 通过id删除
     * @param id id
     */
    @Delete("delete from product where id = #{id}")
    void deleteById(int id);
}

  • service
package zi10ng.service;

import zi10ng.domian.Product;

import java.util.List;

/**
 * @author zi10ng
 * @date 2019年7月18日16:22:06
 */
public interface ProductService {
    /**
     * 查询所有产品
     * @return list形式
     */
    List<Product> findAll();

    /**
     * 通过id删除
     * @param id id
     */
    void deleteById(int id);
}

  • controller
package zi10ng.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import zi10ng.domian.Product;
import zi10ng.service.ProductService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Zi10ng
 * @date 2019年7月18日16:24:18
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;
    private final String LIST = "list";

    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Product> all = productService.findAll();
        model.addAttribute("list",all);
        return LIST;
    }

    @RequestMapping(value = "/delete",params = "id")
    public void deleteById(int id, HttpServletRequest request, HttpServletResponse response) throws IOException {
        productService.deleteById(id);
        response.sendRedirect(request.getContextPath() + "/product/findAll");
    }
}
项目结构

在这里插入图片描述

  • 注:jsp那里写错了,应该是返回到过滤器,然后再监听,之后再发送给browser

源码地址

ssm所需所有jar包 ssm框架所需的所有jar包整合,以及javaben等所有计算的jar包整合 立即下载

相关推荐

基于Q-learning的无人机三维路径规划(含完整C++代码)

基于Q-learning的无人机三维路径规划(含完整C++代码)

weixin_54186646的博客 1万+

SSM整合,手把手教程,详解思路讲解

SSM(Spring+SpringMVC+MyBatis)框架集由Spring、MyBatis两个开源框架整合而成(SpringMVC是Spring中的部分内容),常作为数据源较简单的web项目的框架。虽然现在后端主流开发API的框架是springboot,但ssm的学习依然重要,也是springboot的基石。 很多人说ssm配置起来太麻烦了,不如springboot,看完我这篇,让你在ssm阶段像SpringBoot一样快速搭建,大大提高开发效率 项目搭建 一,工程创建 1.新建Ma

liyingjie2001的博客 1万+

基于微信小程序的扫码签到系统源码

大等于jdk1.8,大于mysql5.5,idea(eclipse),微信开发者工具。代码注释齐全,没有多余代码,适合学习(毕设),二次开发,包含论文技术相关文档。签到管理:新增签到,点击查看码展示二维码(有时效性)springboot mybatis 小程序。签到管理:查看用户创建的签到,可删除。用户管理:查看注册用户信息,及删除。签到记录:查看用户签到记录:可删除。个人信息:展示个人信息,可修改。统计分析:查看用户,签到数量。签到记录:查看用户签到记录。登录注册(含授权登录)我的签到:查看签到记录。

wfuhui的博客 5224

SSM的整合

记录SSM的整合过程。

瞭望红尘的博客 3580

MOBsf联动雷电模拟器(在docker国内库撤销后)

MobSF (全称:Mobile Security Framework,中文名:移动安全框架) 是一个自动化的移动应用程序(Android / iOS / Windows)开源测试工具,该工具采用Python开发,能够执行静态,动态和恶意软件分析。MobSF提供了很多自动化分析功能,尤其适用于Android应用。安装必备(默认已准备好)docker(kali) 现在的国内镜像源都已经下架了只能开代理下载桌面版然后给pull到本地。

qq_48149564的博客 1600

艾德克斯电子负载IT8510维修

2年前从朋友那收了这台艾德克斯电子负载,收来的时候上面的编码器就不好用,就是旋转的时候一会增加一会减小这种现象,不过其他功能都是正常的,自己也就将就用这。直到昨天,电子负载开机发现空载的时候电压不是0,开始有mV级的跳动,心想这个不正常。又测试了一下恒流功能,已经不能正常工作了。

mainbanp 4650

SSM整合完整流程讲解

Spring的IOC容器创建先于SpringMVC的IOC容器SpringMVC扫描的是controller包,Spring要把其他的包扫描了,两个框架管理各自的组件了解监听器的作用,在服务器启动的时候加载Spring的配置文件Spring配置文件代替原来的 mybatis-config.xml其余的配置与单独使用时基本一致。...

小鲁蛋的博客 8930

[亚信线上教学] AX58100: EtherCAT从站设备仿真功能设计教学

什么情况需要开启EtherCAT从站设备仿真功能呢? 一般来说, 当EtherCAT从站产品,不需要使用额外的微控制器介入,或使用不具备EtherCAT从站通讯协议栈的微控制器一同协作的情况下,就必须开启EtherCAT从站设备仿真功能,这样EtherCAT主站才能够正常设置从站设备的工作状态. 亚信AX58100 EtherCAT从站控制芯片的优点 AX58100 EtherCAT从站控制器, 集成2个百兆以太网Phis, 并支持一些额外的控制接口, 例如脉冲宽度调变, 增量, 霍尔编码器, .

allanchou1的专栏 7422

SSM整合

ssm

weixin_68507438的博客 2719

如何实现电路级别的CDM ESD防护

采用先进制程的CMOS工艺,可能具有比以前更薄的栅极氧化物和更大的芯片尺寸,大的衬底可能积累大量的电荷,导致CDM事件期间的高ESD放电峰值电流。传统CDM保护器件使用栅极接地NMOS被添加到输入级的栅极。然而,这种方法通常会在信号路径上引入显著的寄生电容,这不适合RF应用。

weixin_42693135的博客 2500

Android - 蓝牙开发

文章目录科普SIG类型制式编程Classic BluetoothBluetooth Low Energy蓝牙的UUID是什么?有什么用? 科普 https://zh.wikipedia.org/wiki/%E8%97%8D%E7%89%99 蓝牙(英语:Bluetooth),一种无线通讯技术标准,用来让固定与移动设备,在短距离间交换资料,以形成个人局域网(PAN)。其使用短波特高频(UHF)无线电波,经由 2.4 至 2.485 GHz 的 ISM(工业、科学、医疗)频段来进行通信。1994 年由电信商

qq_43323826的博客 1万+

SSM框架整合思想及步骤

SSM框架即是将SpringMVC框架、Spring框架、MyBatis框架整合使用。以简化在web开发中繁琐、重复的操作,让开发人员的精力专注于业务处理的开发上。ssm框架根据SpringMVC、Spring、MyBatis三者各自的特性及应用场景对其操作的的业务进行了分割,降低了耦合性。SpringMVC框架位于Controller层,主要为接收用户发起的请求,在接收请求后可进行一定处理(如:通过拦截器的信息验证处理)。在通过处理后SpringMVC会根据请求的路径将请求分发到对应的Controller

发果叁 1万+

【人工智能】向量数据库全生命周期数据安全防护体系:破解向量化与检索双环节泄露风险

大模型时代,向量数据库已成为RAG(检索增强生成)架构、语义检索、多模态应用的核心基础设施,解决了大模型幻觉、长上下文窗口限制、私有知识落地等核心痛点。但行业普遍存在认知误区:将Embedding向量等同于“无害的语义压缩乱码”,忽视了向量数据原生的泄露风险。

奶爸的编程之路,也就一周冷个三天 156

SSM框架整合

MVC设计模式代表(模型视图控制器) 模式,这种模式用于应用程序的分层开发,解决了应用程序中业务逻辑、数据和界面显示的耦合问题,SSM框架就是实现了MVC设计模式的具体框架。SSM框架分别是指SpringSpringMVC和MyBatis框架的组合。

像污秽一样的博客 2743

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

SSM 整合笔记

微观:将学习的 Spring SpringMVC Mybatis 框架应用到项目中!SpringMVC 框架负责控制层Spring 框架负责整体和业务层的声明式事务管理MyBatis 框架负责数据库访问层宏观:Spring 接管一切(将框架核心组件交给 Spring 进行 IoC 管理),代码更加简洁。SpringMVC 管理表述层、SpringMVC 相关组件Spring管理业务层、持久层、以及数据库相关(DataSource,MyBatis)的组件使用IoC的方式管理一切所需组件。

weixin_57796792的博客 1514

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

SSM整合过程梳理

框架用的好效率自然高

懒羊羊的博客 2981

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

SSM整合完整流程

✅作者简介:大家好,我是Leo,热爱Java后端开发者,一个想要与大家共同进步的男人😉😉 🍎个人主页:Leo的博客 💞当前专栏: SSM专栏 ✨特色专栏: MySQL学习 🥭本文内容:SSM整合完整流程 🖥️个人小站 :个人博客,欢迎大家访问 📚个人知识库: 知识库,欢迎大家访问Spring 和 SpringMVC 本身就是同源的,作为 Spring 家族的一个框架,整合不整合都行,我们所说的不整合是指 Spring 和 SpringMVC 创建同一个 IOC 容器,整合是指 Spring 和

分享思想,留下痕迹。 2162

ssm整合步骤

IDEA整合SSM 什么是ssm? Spring + SpringMVC + Mybatis 1.整合工程 1.创建Maven工程 方式一:使用Web模板 方式二: 1.在main目录下新建目录webapp 2.建立web工程 注意路径问题 3.配置 Tomcat 基本目录结构就搭建完毕 4.Maven导入相关依赖 Spring SpringMVC Mybatis 数据库连接池,数据库连接驱动 日志,测试单元 pom.xml <?xml version="1.0" encoding="U

CrazyAugust的博客 5434

SSM 整合详细步骤

SSM 整合 第一章环境准备 1、创建数据库和表结构 create database ssm; create table account( id int primary key auto_increment, name varchar(100), money double(7,2), ); 2、创建 Maven 工程 创建ssm_parent父工程(打包方式选择pom,必须的) 创建ssm_web子模块(打包方式是war包) 创建ssm_service子模块(打包方式是jar包) 创建ssm_dao子模

你好,摆渡人的博客 3049

SpringBoot之整合SSM步骤

传统的JavaWeb开发中,Spring、SpringMVC和MyBatis(SSM)的整合需要繁琐的配置,涉及大量XML文件,而SpringBoot的出现,通过自动配置和起步依赖,极大简化了SSM的整合过程。

aa_hdkf_vg的博客 1390

ssm整合原理

ssm是指Spring、SpringMVC、mybatis,现在web开发的三驾马车。 一,整合的目标是什么? 所谓的整合都是基于spring框架的,spring是一个java应用开发框架,最大的特点就是替开发者创建对象,是一个生产对象的大工厂。 java是面向对象的语言,简单来说,开发java应用程序典型步骤是: ① 创建一个类; ② 创建这个类的对象; ③ 调用这...

epitomizelu的专栏 1245
上一篇: abstract isClosed()Z of interface java.sql.ResultSet
下一篇: 力扣136-只出现一次的数字
王星星的魔灯
博客等级 码龄9年 871粉丝 142原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值