Java框架_SpringMVC_day04_响应数据

深入浅出ISP:用RKISP2.x Tuner工具理解AWB、AE、HDR等核心模块的实战调参 本文深入解析RKISP2.x Tuner工具在ISP图像处理中的实战应用,重点探讨AWB、AE、HDR等核心模块的调参技巧。通过环境搭建、调试工具使用和实际案例,帮助开发者掌握如何在不同光照条件下优化图像质量,实现精准的白平衡、曝光控制和动态范围处理。 阅读详情

目录

五、数据相应和结果视图

5.1 开发准备

5.1.1 导入jar包

5.1.2 配置 web.xml

5.1.3 springmvc.xml

5.1.4 index.jsp

5.1.5 success.jsp

5.1.6 Controller

5.2 返回值为字符串

5.2.1 response.jsp

5.2.2 Controller

5.2.3 update.jsp

5.2.4 点击提交

5.3 返回值为 void

5.3.1 response.jsp

5.3.2 Controller

5.4 返回值是 ModelAndView 对象

5.4.1 response.jsp

5.4.2 Controller

5.4.3 导入 jstl 的坐标

5.4.4 success.jsp(遍历 list )

5.5 SpringMVC 框架提供的转发和重定向

5.5.1 response.jsp

5.5.2 forward 请求转发

5.5.3 redirect 重定向

5.6 @ResponseBody 响应 json 数据

5.6.1 去掉静态资源的拦截

5.6.2 使用 @RequestBody 获取请求的数据

5.6.3 使用 @ResponseBody 注解将 JavaBean 对象转换成 Json 返回

5.6.4 Jackson 的 jar 包

5.6.5 小结


五、数据相应和结果视图

5.1 开发准备

5.1.1 导入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.cpz</groupId>
    <artifactId>springmvc_response</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <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>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.0</version>
        </dependency>
    </dependencies>
</project>

5.1.2 配置 web.xml

<!-- SpringMVC的核心控制器 -->
<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 配置Servlet的初始化参数,读取springmvc的配置文件,创建spring容器 -->
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <!-- 配置servlet启动时加载对象 -->
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<!--处理乱码的过滤器-->
<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>

5.1.3 springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       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.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 1:配置spring创建容器时要扫描的包 -->
    <context:component-scan base-package="com.cpz"></context:component-scan>
    <!-- 2:配置视图解析器 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <!-- 3:配置spring开启注解mvc的支持 -->
    <mvc:annotation-driven></mvc:annotation-driven>
</beans>

5.1.4 index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<h1>响应测试</h1>
<a href="user/testUserController">测试UserController</a>
<hr/>

</body>
</html>

5.1.5 success.jsp

<body>
<h1>访问成功</h1>
</body>

5.1.6 Controller

@Controller
@RequestMapping(value = "/user")
public class UserController {

    @RequestMapping(value = "/testUserController")
    public String testUserController(){
        System.out.println("执行了 UserController 的 testUserController 方法 !!! ");
        return "success";
    }
}

5.2 返回值为字符串

5.2.1 response.jsp

<body>
<h3>返回字符串</h3>
<a href="user/testReturnString">返回字符串</a><br>
<a href="user/userUpdate">修改用户(表单回显)</a>
</body>

5.2.2 Controller

    @RequestMapping(value = "/testReturnString")
    public String testReturnString(){
        System.out.println("执行了 UserController 的 testReturnString 方法 !!! ");
        return "success";
    }

    @RequestMapping(value = "/testUserUpdate")
    public String testUserUpdate(Model model){
        System.out.println("执行了 UserController 的 testUserUpdate 方法 !!! ");
        // 模拟从数据库中查询的数据,在页面上进行回显
        User user = new User();
        user.setUsername("张三");
        user.setPassword("123456");
        user.setAge(22);
        model.addAttribute("user",user);
        return "update";
    }

5.2.3 update.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<h3>修改用户</h3>
<%--${ requestScope }--%>
<form action="${ pageContext.request.contextPath }/user/update" method="post">
    <input type="text" name="username" value="${ user.username }"/><br/>
    <input type="text" name="password" value="${ user.password }"/><br/>
    <input type="text" name="age" value="${ user.age }"/><br/>
    <input type="submit" value="提交"/><br/>
</form>

</body>
</html>

5.2.4 点击提交

    @RequestMapping(value = "/update")
    public String update(User user){
        System.out.println("执行了 UserController 的 update 方法 !!! ");
        System.out.println(user);
        return "success";
    }

5.3 返回值为 void

5.3.1 response.jsp

<h3>无返回值void</h3>
<a href="user/testVoid">无返回值</a>

5.3.2 Controller

    @RequestMapping(value = "/testVoid")
    public void testVoid(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("执行了 UserController 的 testVoid 方法 !!! ");
        // 可以使用请求转发或者重定向跳转到指定的页面
        // 请求转发
        // request.getRequestDispatcher("/WEB-INF/pages/success.jsp").forward(request,response);
        // 重定向
        //response.sendRedirect(request.getContextPath()+"/user/testReturnString");

        // 如果不指定转发和重定向,直接响应数据
        // 直接响应数据
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        response.getWriter().println("你好");
    }

【小结】void:执行视图解析器(如果不想通过视图解析器指定页面路径,可以通过自定义转发和重定向完成页面跳转)

5.4 返回值是 ModelAndView 对象

5.4.1 response.jsp

<h3>返回ModelAndView对象</h3>
<a href="user/testModelAndView">ModelAndView</a><br/>

5.4.2 Controller

    @RequestMapping(value = "/testModelAndView")
    public ModelAndView testModelAndView(){
        System.out.println("执行了 UserController 的 testModelAndView 方法 !!! ");
        ModelAndView mv = new ModelAndView();
        // 默认执行视图解析器,跳转到WEB-INF/pages/success.jsp的页面
        mv.setViewName("success");

        // 模拟从数据库中查询所有的用户信息
        List<User> list = new ArrayList<User>();
        User user = new User();
        user.setUsername("zhangsan");
        user.setAge(22);

        User user2 = new User();
        user2.setUsername("lisi");
        user2.setAge(20);

        list.add(user);
        list.add(user2);
        mv.addObject("list",list);
        return mv;
    }

5.4.3 导入 jstl 的坐标

<dependency>
  <groupId>jstl</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>

5.4.4 success.jsp(遍历 list )

<h3>查询所有的数据</h3>
<c:forEach items="${ list }" var="user">
    ${ user.username } --- ${ user.age }
</c:forEach>

【小结】ModelAndView在企业中应用较多,执行视图解析器(既有模型的功能,也有视图的功能)

5.5 SpringMVC 框架提供的转发和重定向

5.5.1 response.jsp

<h3>转发和重定向</h3>
<a href="user/testForwardOrRedirect">ForwardOrRedirect</a>

5.5.2 forward 请求转发

    @RequestMapping(value = "/testForwardOrRedirect")
    public String testForwardOrRedirect(){
        System.out.println("执行了 UserController 的 testForwardOrRedirect 方法 !!! ");
//        return "forward:/WEB-INF/pages/success.jsp";
        return "forward:/user/testReturnString";
    }

5.5.3 redirect 重定向

    @RequestMapping(value = "/testForwardOrRedirect")
    public String testForwardOrRedirect(){
        System.out.println("执行了 UserController 的 testForwardOrRedirect 方法 !!! ");
//        return "redirect:/WEB-INF/pages/success.jsp"; //不成功!!
        return "redirect:/user/testReturnString";
    }

5.6 @ResponseBody 响应 json 数据

5.6.1 去掉静态资源的拦截

<!--方案一:-->
<!-- 设置静态资源不过滤 -->
<mvc:resources location="/js/" mapping="/js/**"/> 
<!--方案二:-->
<!--去掉所有的静态资源,让DispatchServlet不能拦截静态资源-->
<mvc:default-servlet-handler></mvc:default-servlet-handler>

5.6.2 使用 @RequestBody 获取请求的数据

response.jsp

<script src="js/jquery.min.js"></script>
<script>
    $(function () {
        $("#btn").click(function () {
            //alert("ok");
            $.ajax({
                url:"user/testJson",
                contentType:"application/json;charset=UTF-8",
                data:'{"username":"tom","password":"123","age":"25"}',
                dataType:"json",
                type:"post",
                success:function (data) {
                    alert(data);
                    alert(data.username);
                    alert(data.password);
                    alert(data.age);
                }
            });
        })
    })
</script>

5.6.3 使用 @ResponseBody 注解将 JavaBean 对象转换成 Json 返回

Controller

    @RequestMapping(value = "/testJson")
    @ResponseBody
    public User testJson(@RequestBody User user){
        System.out.println("执行了 UserController 的 testJson 方法 !!! ");
        System.out.println(user);

        User u = new User();
        u.setUsername("张三");
        u.setPassword("123456");
        u.setAge(30);

        return u;
    }

5.6.4 Jackson 的 jar 包

json 字符串和 JavaBean 对象相互转换的过程中,需要使用 jackson 的 jar 包

<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.9.0</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
  <version>2.9.0</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-annotations</artifactId>
  <version>2.9.0</version>
</dependency>

5.6.5 小结

@RequestBody的使用(json字符串-->javabean)

@ResponseBody的使用(javabean-->json字符串

 

为什么你的SSE连接总断?深入对比EventSource与fetch-event-source的5大差异点 本文深入对比了原生EventSource与@microsoft/fetch-event-source库在SSE连接稳定性上的五大关键差异。重点剖析了后者在请求能力、连接控制、错误处理、数据解析及性能优化方面的优势,特别是其支持POST请求、自定义Header、精细化的重连策略与生命周期管理,为解决生产环境中SSE连接频繁断开的问题提供了专业方案。 阅读详情

相关推荐

语义分割系列7-Attention Unet(pytorch实现)

本文介绍了AttentionUnet模型和其主要中心思想,并在pytorch框架上构建了Attention Unet模型,构建了Attention gate模块,在数据集Camvid上进行复现。

yumaomi的博客 2万+

spring mvc controller接收请求值及controller之间跳转及传值

spring mvc controller接收请求值及controller之间跳转及传值

SayNight 4万+

Uniapp+Vue3+Monorepo:如何优化你的前端开发流程(附完整配置代码)

本文详细介绍了如何利用Uniapp+Vue3+Monorepo技术栈优化前端开发流程,提升代码可维护性和团队协作效率。通过Monorepo架构实现依赖管理智能化、代码复用最大化和构建流程统一化,结合完整配置代码和实战指南,帮助开发者快速构建高性能跨端应用。

weixin_29011993的博客 453

SpringMVC-03-响应数据和结果视图

SpringMVC-HMday02-01-响应数据和结果视图

Allure泽宇的博客 828

基于ROS下的安卓手机图像和IMU跑ORB-SLAM3

接之前文章继续,手上没有现成的单目+IMU硬件,但是安卓手机几乎人人都有。因此,本文讲下如何用手机跑ORB-SLAM3的Mono和Mono_Inertial。 1. 手机与PC通信 基于ROS下的信息发布和订阅,手机和PC在一个局域网下进行信息(image和IMU)传输。 手机APK参考了github上的2个开源Android_Camera-IMU和android_ros_sensors,基于ros_java生成安卓APP,下载安装任一个APP到安卓手机,界面分别是这样: 手机和PC连一个无

h_372101的博客 1万+

Ubuntu安装pytorch3d的最便捷方法【原创】

Ubuntu安装pytorch3d的最便捷方法

qq_54900679的博客 2924

SpringMVC-学习笔记04【SpringMVC返回值类型及响应数据类型】

SpringMVC-学习笔记04【SpringMVC返回值类型及响应数据类型】

upward 1286

openwrt编译及第一个安装包教程

Date: 2017.03.14 Made:SuperDeverloper Email: na1206@live.com Target: For mt7688 based board说明:本人在学习过程中走了不少弯路,希望本文档能为后来者提供便利。欢迎复制和使用本文档。本文档记录了搭建openwrt编译环境以及快速创建ipk包(openwrt上的安装程序)。本文档在实际应用中做过几次修改,以帮

SuperDevloper的博客 1万+

day56 JavaWeb框架阶段——SpringMVC的请求和响应(SpringMVC的数据响应,SpringMVC的数据请求)

今日内容:SpringMVC的请求和响应 今日源码: 链接:https://pan.baidu.com/s/1U1sIKmCyK0kFchcisTPT0g 提取码:7843 1. SpringMVC的数据响应和请求 01-SpringMVC的数据响应-数据响应方式(理解) 页面跳转 直接返回字符串 通过ModelAndView对象返回 2) 回写数据 直接返回字符串 返回对象或集合 02-Sp...

qq_38454176的博客 321

YOLO11改进-注意力-引入级联组注意力机制(Cascaded Group Attention, CGA)

输入特征拆分:输入特征进入 CGA 模块后,被均匀拆分为个部分,每个部分作为一个注意力头的输入,这样每个头关注输入特征的不同部分,实现特征的并行处理,同时为提高注意力多样性奠定基础。注意力头计算单元:每个注意力头包含三个线性投影层、、用于将输入特征映射到不同子空间,以及计算自注意力的单元。在计算过程中,通过注意力头之间的级联操作,前一个头的输出会累加到下一个头的输入上,实现特征的逐步细化。

qq_64693987的博客 2489

断层错动和近断层地震动联合作用下软岩隧洞衬砌损伤分析

摘要 本文提出了一种基于Python的软岩隧洞衬砌损伤分析系统,重点研究断层错动和近断层地震动的联合作用效应。系统采用有限元方法建立隧洞-围岩体系模型,通过非线性动力分析评估衬砌结构损伤。研究内容包括:1)建立考虑应变软化的软岩本构模型;2)基于位错理论模拟断层错动过程;3)合成具有速度脉冲效应的近断层地震动;4)开发完整的动力响应分析流程。结果表明,所提出的方法能有效评估软岩隧洞在复杂地质条件下的抗震性能,为工程设计提供理论依据。 关键词:软岩隧洞、断层错动、近断层地震动、损伤分析、Python、有限元法

max500600的博客 842

黑马程序员——Spring框架——day04——SpringMVC基础

Servlet属于web层开发技术,技术特点:每个请求都需要创建一个Servlet进行处理创建Servlet存在重复操作代码灵活性低,开发效率低是否有技术方案可以解决以上问题?SpringMVC是一种基于Java实现MVC模型的轻量级Web框架优点使用简单、开发便捷(相比于Servlet)灵活性强代码编写完后,我们要想测试,只需要打开浏览器直接输入地址发送请求即可。但是我们如果我们发送的是GET请求可以直接使用浏览器,但是如果要发送的是POST请求呢?

qq_56444564的博客 908

RuyiDify如何创建知识库API密钥:让程序安全访问知识库

知识库 API Key 是程序访问知识库的钥匙。创建它很简单,但真正重要的是知道它能做什么、应该放在哪里、不能暴露给谁。RuyiDify 讲这一步,不是为了让大家多记一个按钮,而是为了把知识库从“人工上传资料”推进到“程序化维护资料”。

未来已来,AI时代,学AI编程,做AI量化,就来大鹏AI教育。 136

day04-SpringMVC_01

一个类只能处理一个请求参数接收非常不方便。无法直接接收json数据和java对象类型数据响应数据也非常不方便。无法和spring框架天然兼容。SpringMVC框架有什么优点?轻量级 - 上手容易、体量小、半自动、(学习成本)SpringMVC接收请求、给出响应,负责MVC层处理!!!SpringMVC是一种基于Java实现MVC模型的轻量级Web框架优点使用简单,开发便捷(相比于Servlet)灵活性强接收请求、给出响应//定义表现层控制器bean。

qq_74289024的博客 1195

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

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

三天学习SpringMVC框架之Day02

SpringMVC的请求和响应 SpringMVC的数据响应 01-SpringMVC的数据响应-数据响应方式(理解) (三张思维导图教您更高效学习SSM框架) 页面跳转 直接返回字符串 通过ModelAndView对象返回 2) 回写数据 直接返回字符串 返回对象或集合 02-SpringMVC的数据响应-页面跳转-返回字符串形式(应用) 03-SpringMVC的数据响应-页面跳转-返回...

简简单单的博客 403

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

day06_SpringMVC的请求和响应

SpringMVC的请求和响应 SpringMVC的数据响应 01-SpringMVC的数据响应-数据响应方式(理解) 页面跳转 直接返回字符串 通过ModelAndView对象返回 2) 回写数据 直接返回字符串 返回对象或集合 02-SpringMVC的数据响应-页面跳转-返回字符串形式(应用) 03-SpringMVC的数据响应-页面跳转-返回ModelAndView形式1(应用) 在Controller中方法返回ModelAndView对象,并且设置视图名称 @RequestMapping(

Jenius87v5的博客 280

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

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

DAY04_SpringMVC—SpringMVC简介&PostMan和ApiFox工具使用&SpringMVC请求与响应&REST风格

SpringMVC—SpringMVC简介、PostMan和ApiFox工具使用、SpringMVC请求与响应、REST风格

m0_57075290的博客 1805

SpringMVC框架day04之数据输出(一)

springmvc.xml 包扫描 context: 前端控制器InternalViwResolver web.xml 3. 字符编码过滤器CharacterEncodingFilter 4. Rest风格过滤器HiddenFilter(_method的put和delete删改请求) 使用原生API向request和session域中保存数据 使用springmvc ...

程序彤的博客 182

SpringMVC Day 04 : 数据绑定

数据绑定是一种编程技术,用于将数据模型的值自动地与用户界面元素(如文本框、标签、下拉菜单等)进行同步。当数据模型中的值发生变化时,这些变化会自动地反映在用户界面元素中,反之亦然。数据绑定可以减少开发人员的工作量,提高应用程序的可维护性和可重用性。数据绑定可以分为单向绑定和双向绑定两种类型。单向绑定是指只有在数据模型中的值发生变化时,才会更新用户界面元素的值。而双向绑定则是指在数据模型中的值发生变化时,不仅会更新用户界面元素的值,同时也会将用户界面元素中的值更新到数据模型中。

zhiqiuqiu2的博客 797

springmvc_day02

SpringMVC_day02-请求和响应 SpringMVC的数据响应 01-SpringMVC的数据响应-数据响应方式(理解) 页面跳转 直接返回字符串 通过ModelAndView对象返回 2) 回写数据 直接返回字符串 返回对象或集合 02-SpringMVC的数据响应-页面跳转-返回字符串形式(应用) 03-SpringMVC的数据响应-页面跳转-返回ModelAndView形式1...

Naker_的博客 227

04_SpringMVC

SpringMVC

GL1765852966的博客 678

04蚂蚁-源码分析——4.手写SpringMVC框架之手写手写@RequestMapping和Controller注解

SpringMVC原理 giti地址mayiedu/src/main/java/com/mayi04/day20/下的项目 SpringMVC的运行流程 ⑴ 用户发送请求至前端控制器DispatcherServlet ⑵ DispatcherServlet收到请求调用HandlerMapping处理器映射器。 ⑶ 处理器映射器根据请求url找到具体的处理器,生成处理器对象及处理器拦截器(如果有则...

qq_28461661的博客 458

Java Spring|day2.SpringMVC

ajax 全名 async javascript and XML(异步JavaScript和XML)Ajax是一种用于创建快速动态网页的技术。通过在后台与服务器进行少量数据交换,Ajax可以使网页实现异步更新。这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行更新。而传统的网页(不使用 Ajax)如果需要更新内容,必需重载整个网页面。

weixin_60364343的博客 798

SpringMVC-学习笔记01【SpringMVC概述及入门案例】

SpringMVC-学习笔记01【SpringMVC概述及入门案例】

upward 1364
上一篇: Java框架_SpringMVC_day03_注解开发
下一篇: Java框架_SpringMVC_day05_文件上传
chipeize
博客等级 码龄10年 23粉丝 80原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值